IC SunsetThe developerWorks Connections platform will be sunset on December 31, 2019. On January 1, 2020, this community and its apps will no longer be available. More details available on our FAQ.
Topic
  • No replies
z.cristiano
z.cristiano
1 Post

Pinned topic Upload file with XMLHttpRequest

‏2011-07-18T14:53:05Z |
Hello, i have create e form with ajax for upload file with XMLHttpRequest

page.php

<script>

function upload()
{

var file_upload = document.form1.file_upload.files;

/*
if(xmlhttp5.readyState == 1)
{

alert("Attendere!");

} else
*/

// code for IE7+, Firefox, Chrome, Opera, Safari
if(window.XMLHttpRequest)
{

xmlhttp5 = new XMLHttpRequest();

} else {

// code for IE6, IE5
xmlhttp5 = new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp5.onreadystatechange = function()
{

if(xmlhttp5.readyState == 4 && xmlhttp5.status == 200)
{

alert(xmlhttp5.responseText);

}

}

xmlhttp5.open("PUT", "upload.php?file_upload="+ file_upload, true);
xmlhttp5.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

xmlhttp5.send();

}

</script>
<form name="form1" id="form1" method="post" enctype="multipart/form-data">
<input type="file" name="file_upload" id="file_upload" /><input type="button" value="Upload" onclick="upload();">
</form>

upload.php

<?php

copy($_FILES, $_FILES);
echo"OK";

?>

Don't work and don't upload, why?
Sad