w3c / web-share-target

Web API proposal for receiving shared data
https://w3c.github.io/web-share-target/
Other
191 stars 20 forks source link

How to share a file as if it was a <input type="file"> POST request. #105

Closed katistix closed 3 years ago

katistix commented 3 years ago

I want to be able to take the shared file (for example an image) and then with PHP I can use eighter $_FILES or $_POST to take the data from that file. PS: I already have send.php which sends a POST request to upload.php which takes care of the file and does it's serverside stuff. manifest.json

"share_target": {
    "action": "upload.php",
    "method": "POST",
    "enctype": "multipart/form-data",
    "params": {
      "name": "file",
      "files": [
        {
          "name": "fileToUpload",
          "accept": [".pdf", ".jpg", ".png", ".jpeg", ".doc", ".docx", ".pdf", ".xls", ".xlsx", ".txt", ".mp4", ".mp3", ".wav", ".rar", ".zip"]
        }
      ]
    }
  }

And uplaod.php (here is just a part of the code that I already have) $filename = basename($_FILES["fileToUpload"]["name"]);

So I want my servevr to think that the file was selected on send.php in a <form> Just for reference, here is the form from send.php:

<form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="fileToUpload" id="fileToUpload" class="select_button">
        <input onclick="showLoader()" type="submit" value="Send" name="submit" class="sendBtn btnAnimated">
</form>