I can't find what's wrong with my javascript-ajax-php "upload file" code -
this first question here (usually find own ways solve problems) can't find problem in file upload code. it's supposed utilize ajax. simplified easier read. here html form:
<form id="fileform" enctype="multipart/form-data" method="post" action="php/uploadfile.php"> <p>insert file: <input type="file" id="fileup" name="fileup" /> <button type="submit" id="uploadbutton" onclick="sendfile();">upload</button></p> </form>
now here goes javascript sendfile() function:
function sendfile() { var forma = document.getelementbyid("fileform"); var failas = document.getelementbyid("fileup"); var uploadbutton = document.getelementbyid("uploadbutton"); forma.onsubmit = function(event) { event.preventdefault(); } uploadbutton.innerhtml = "uploading, please wait!"; var newfile = failas.files[0]; var formdata = new formdata(forma); formdata.append("fileup", newfile, newfile.name); alert(newfile.name);// here says filename.jpg means ok @ stage xmlhttp = new xmlhttprequest(); xmlhttp.onreadystatechange = function() { if(xmlhttp.readystate == 4 && xmlhttp.status == 200) { alert (xmlhttp.responsetext); } } xmlhttp.open("post", "php/uploadfile.php", true); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.send(formdata); }
and php:
<?php echo var_dump($_files); ?>
it should alert contents of $_files, says array(0){} if seek $_request. so, if suggest may wrong, appreciated :]
javascript php html ajax
No comments:
Post a Comment