Retrieve Uploaded Blob with PHP

前端 未结 2 1894
暖寄归人
暖寄归人 2021-02-15 16:39

I have a script that is creating a blob and posting it to a PHP file. Here is my code:

HTML/Javascript:



        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-15 17:21

    The data from the blob can be read from php://input, as in

    If however you want to send multiple pieces of data with a form data object it would be like a normal multipart/form-data post. All string would be available through $_POST and all blobs and file through $_FILES.

    function upload() {
    
        var data = new FormData();
        var oReq = new XMLHttpRequest();
        oReq.open("POST", 'upload.php', true);
        oReq.onload = function (oEvent) {
          // Uploaded.
        };
    
        var blob = new Blob(['abc123'], {type: 'text/plain'});
        data.append('file', blob);
        oReq.send(data);
    }
    

提交回复
热议问题