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?
:-(

Member Avatar for stbuchok

Not 100% sure, but shouldn't it be POST, not PUT? Someone please correct me if I'm wrong.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.