file uploading with html5 and ajax issue
Posted: Wed Apr 06, 2011 12:43 pm
ok I am having issues with my file size changing after I upload.
var reader = new FileReader();
reader.readAsBinaryString(file);
I send the file object like this...
when I output the size of the file object in javascript
file.length
it returns with the value 69,874 bytes which is the exact file size.
after the post on the php end of thing I use this simple code to read the file
it returns the size 88648 bytes
where is the extra data coming from do you guys have any idea?
var reader = new FileReader();
reader.readAsBinaryString(file);
I send the file object like this...
Code: Select all
var http = new XMLHttpRequest();
var url = "upload.php";
http.open("POST", url, true);
//Send the proper header information along with the request
//http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//http.setRequestHeader("Content-length", 0);
//http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
div.innerHTML = http.responseText;
}
}
http.send(file);
file.length
it returns with the value 69,874 bytes which is the exact file size.
after the post on the php end of thing I use this simple code to read the file
Code: Select all
<?php
$postdata = file_get_contents("php://input");
echo "File size on the server is: ".strlen(stripslashes($postdata))." bytes. <br />";
echo $postdata;
$fp = fopen("fighter.txt", "wb");
fwrite($fp, $postdata);
fclose($fp);
?>
where is the extra data coming from do you guys have any idea?