Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to upload a file through jQuery .post() - file input not showing up on back end (using codeigniter)
    text
    copied!<p>First of all I'd like to ask that you don't suggest I turn to a jQuery plugin to solve my issue. I'm just not willing to make my app work with a plugin (and it prevents me from learning!)</p> <p>I have a form with a bunch of fields that I'm passing to my backend via the use of jQuery's <code>$.post()</code> This is what I have as my jQuery function:</p> <pre><code> $.post( "/item/edit", $("#form").serialize(), function(responseJSON) { console.log(responseJSON); }, "html" ); </code></pre> <p>This is how I opened my form: </p> <pre><code>&lt;form action="http://localhost/item/edit" method="post" accept-charset="utf-8" class="form-horizontal" enctype="multipart/form-data"&gt; </code></pre> <p>This was auto generated by codeigniter's <code>form_open()</code> method (hence why action="" has a value. Though this shouldn't matter because I don't have a submit button at the end of the form)</p> <p>Within my <code>#form</code> I have this as my file input: <code>&lt;input type="file" name="pImage" /&gt;</code></p> <p>When the appropriate button is hit and the <code>$.post()</code> method is called, I have my backend just print the variables like so: <code>print_r($_POST)</code> and within the printed variables the 'pImage' element is missing. I thought that maybe files wouldn't come up as an element in the array so I went ahead and just tried to upload the file using this codeigniter function: <code>$this-&gt;upload-&gt;do_upload('pImage');</code> and I get an error: "You did not select a file to upload."</p> <p>Any idea as to how I can overcome this problem?</p>
 

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