Note that there are some explanatory texts on larger screens.

plurals
  1. POPutting input file into FormData jquery to submit to PHP
    primarykey
    data
    text
    <p>I know already got question for this problem but i still cant did it properly. Need some help.</p> <p>I need to upload a file with additional data with it. </p> <p><strong>my input.php:</strong></p> <pre><code>&lt;input type="file" id="foto_path" name="foto_path" /&gt; &lt;input type="button" value="Add" onclick="javascript:sendForm()" /&gt; </code></pre> <p><strong>I send that with javascript :</strong> </p> <pre><code>function sendForm() { var fileInput = document.querySelector('#foto_path'); var oMyForm = new FormData(); var nip=123223374;//it will be generated by php, for temporary i just hardcode it oMyForm.append("foto_path", fileInput); oMyForm.append("nip",nip ); var oReq = new XMLHttpRequest(); oReq.open("POST", "upload-file.php", true); oReq.onload = function(oEvent) { if (oReq.status == 200) { //oOutput.innerHTML = "Uploaded!"; alert('success'); } else { //oOutput.innerHTML = "Error " + oReq.status + " occurred uploading your file.&lt;br \/&gt;"; alert('failed'); } }; oReq.send(oMyForm); } </code></pre> <p><strong>and when I send that to upload-file.php:</strong></p> <pre><code>logapp("post -&gt; ".print_r($_POST,true));//logapp is just function to log to file logapp("files -&gt; ".print_r($_FILES,true)); </code></pre> <p><strong>I got this from log:</strong></p> <pre><code>09/07/2013 02:47:06 pm :: post -&gt; Array ( [foto_path] =&gt; [object HTMLImageElement] [nip] =&gt; 123223374 ) 09/07/2013 02:47:06 pm :: files -&gt; Array ( ) </code></pre> <p>I got success alert but I need to get files for <code>foto_path</code> as <code>$_FILES</code> not <code>$_POST</code>. My Question is why input files detected as <code>$_POST["foto_path"]</code> not as <code>$_FILES["foto_path"]</code>. How to change that to <code>$_FILES["foto_path"]</code> so I can start work with the files uploaded?</p>
    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