1

I'm using form data for uploading files code given below

var formData = new FormData();
/* Add the file */ 
formData.append("qqfile", file);
xhr.open("post", 'upload.php', true);
xhr.setRequestHeader("Content-Type", "application/octet-stream");
xhr.send(formData);  /* Send to server */ 

in upload.php my code is given below

$fileReader = fopen('php://input', "r");  
$fileWriter = fopen($this->_destination_file, "w+");  

while(true) {  
    $buffer = fgets($fileReader, 4096);
    if (strlen($buffer) == 0) {  
        fclose($fileReader);  
        fclose($fileWriter);  
        return true;  
    }  

    fwrite($fileWriter, $buffer);  
} 
return false;  

when i'm trying to upload pdf file it's working perfectly, when I'm trying to upload .xls file,file is uploaded but when i open xls file getting non readable character.

8
  • could you change the Content-Type to application/vnd.ms-excel and test again? Commented Aug 26, 2016 at 7:16
  • Tried not working Commented Aug 26, 2016 at 7:24
  • could you do an md5 on the original file and the uploaded file? if they are not the same some content gets stripped while beeing uploaded Commented Aug 26, 2016 at 7:49
  • Content-Type should be "multipart/form-data", please try that Commented Aug 26, 2016 at 7:54
  • 1
    Similar question asked here stackoverflow.com/questions/10091154/php-ajax-file-upload Commented Aug 26, 2016 at 8:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.