I am trying to send img to base64 to the server, javascript looks like
var xhr=new XMLHttpRequest() var reader=new FileReader() reader.onloadend=function(e){ xhr.onload=function(e){ alert(xhr.responseText) } xhr.open("POST","upload.php"); xhr.setRequestHeader("Cache-Control", "no-cache"); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
In php it looks like this:
echo "some response Text"; $postdata = file_get_contents("php://input"); file_put_contents('MyFile.jpg', base64_decode($postdata));
And in the end, the server receives the file exactly the size of the sent file, but it cannot be opened
Does anyone get some ideas? Thank you very much!
source share