Note that there are some explanatory texts on larger screens.

plurals
  1. POupload file through ajax
    primarykey
    data
    text
    <p>I use 2 file index.js, upload.php try to upload file(img) through ajax and if success append to div <code>uploadfile_show</code>.<br> but it doesn't work , have few question and below is my code any suggestion? </p> <p>Thanks.</p> <p>upload.php<br> 1. <code>form enctype</code> still need to add?<br> 2. <code>if($_FILES)</code> and check $_FILES size or tmp_name still use <code>$_FILES</code>?</p> <pre><code>if($_FILES){ $filename = $_FILES['uploadfile']['name']; $filetmp = $_FILES['uploadfile']['tmp_name']; $filesize = $_FILES['uploadfile']['size']; if($filesize &lt; 1000000){ move_uploaded_file($filetmp,'upload/tmp/'.$filename); print" upload success &lt;img src=\"upload/tmp/$filename\"&gt; "; } else{ } } else{ print" &lt;div class=\"uploaddiv\"&gt; &lt;form enctype=\"multipart/form_data\"&gt; &lt;input type=\"type\" name=\"uploadfile\"&gt; &lt;input type=\"submit\" value=\"upload\" class=\"btn\"&gt; &lt;/form&gt; &lt;/div&gt; "; } print" &lt;div class=\"uploadfile_show\"&gt;&lt;/div&gt; "; </code></pre> <p>index.js<br> 3. this few line is it the right?<br> <code>var uf = $('.uploaddiv form');var fd = new FormData(uf);fd.append('uploadfile', uploadfile);</code><br> <code>data: fd,</code><br> 4. any thing I missed or wrong?</p> <pre><code>$('.btn').click(function(){ var uf = $('.uploaddiv form'); var fd = new FormData(uf); fd.append('uploadfile', uploadfile); $.ajax({ type: "POST", url: "upload.php", data: fd, processData:false, contentType: false, success: function(html){ $('.uploadfile_show').append(html); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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