function
upload(fileInputId, fileIndex)
var
file = document.getElementById(fileInputId).files[fileIndex];
var
reader =
new
FileReader();
reader.readAsBinaryString(file);
reader.onloadend =
function
(evt)
xhr =
new
XMLHttpRequest();
xhr.open(
"POST"
,
'upload.php'
,
true
);
XMLHttpRequest.prototype.mySendAsBinary =
function
(text){
var
data =
new
ArrayBuffer(text.length);
var
ui8a =
new
Uint8Array(data, 0);
for
(
var
i = 0; i < text.length; i++) ui8a[i] = (text.charCodeAt(i) & 0xff);
var
bb =
new
(window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)();
var
eventSource = xhr.upload || xhr;
eventSource.addEventListener(
"progress"
,
function
(e) {
var
position = e.position || e.loaded;
var
total = e.totalSize || e.total;
var
percentage = Math.round((position/total)*100);
xhr.onreadystatechange =
function
()
xhr.mySendAsBinary(evt.target.result);
After that make a Php file named upload.php having following code
$fileHandler
=
fopen
(
'/tmp/myfile.tmp'
,
"w+"
);
$buffer
=
fgets
(
$inputHandler
, 4096);
if
(
strlen
(
$buffer
) == 0) {
fwrite(
$fileHandler
,
$buffer
);
?>