Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax and php upload won't move image to upload folder
    text
    copied!<p>Title says it all. When i upload file my code returns the name of the file but not it won't move the image to upload folder.Name of the image works fine so i am not really sure why the file won't go to it's proper destination.</p> <pre><code>index.php &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script&gt; /* Script written by Adam Khoury @ DevelopPHP.com */ /* Video Tutorial: http://www.youtube.com/watch?v=EraNFJiY0Eg */ function _(el){ return document.getElementById(el); } function uploadFile(){ var file = _("file1").files[0]; //alert(file.name+" | "+file.size+" | "+file.type); var formdata = new FormData(); formdata.append("file1", file); var ajax = new XMLHttpRequest(); ajax.upload.addEventListener("progress", progressHandler, false); ajax.addEventListener("load", completeHandler, false); ajax.addEventListener("error", errorHandler, false); ajax.addEventListener("abort", abortHandler, false); ajax.open("POST", "exp.php"); ajax.send(formdata); } function progressHandler(event){ _("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total; var percent = (event.loaded / event.total) * 100; _("progressBar").value = Math.round(percent); _("status").innerHTML = Math.round(percent)+"% uploaded... please wait"; } function completeHandler(event){ _("status").innerHTML = event.target.responseText; _("progressBar").value = 0; } function errorHandler(event){ _("status").innerHTML = "Upload Failed"; } function abortHandler(event){ _("status").innerHTML = "Upload Aborted"; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;HTML5 File Upload Progress Bar Tutorial&lt;/h2&gt; &lt;form id="upload_form" enctype="multipart/form-data" method="post"&gt; &lt;input type="file" name="file1" id="file1"&gt;&lt;br&gt; &lt;input type="button" value="Upload File" onclick="uploadFile()"&gt; &lt;progress id="progressBar" value="0" max="100" style="width:300px;"&gt;&lt;/progress&gt; &lt;h3 id="status"&gt;&lt;/h3&gt; &lt;p id="loaded_n_total"&gt;&lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; exp.php &lt;?php $fileName = $_FILES["file1"]["name"]; // The file name $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["file1"]["type"]; // The type of file it is $fileSize = $_FILES["file1"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } if(move_uploaded_file($fileTmpLoc, "uploads/")){ echo "$fileName upload is complete &lt;img src='uploads/$fileName' width='100' height='100'&gt; "; } else { echo "move_uploaded_file function failed"; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload