Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>how are you trying to echo it?</p> <p>I tested your code and it does what you are asking for. It sends the filenames, but not the files.</p> <p>Run </p> <pre><code>var_dump($_POST['files']) </code></pre> <p>and it'll show you the files' names. <br><br> But If you need to upload files, here is an actual solution :</p> <p>I suggest to use the next libraries <br> 1. AjaxFileUpload (<a href="http://www.phpletter.com/Our-Projects/AjaxFileUpload/" rel="nofollow">http://www.phpletter.com/Our-Projects/AjaxFileUpload/</a>) <br> 2. CodeIgniter Multi-Upload <a href="https://github.com/stvnthomas/CodeIgniter-Multi-Upload" rel="nofollow">https://github.com/stvnthomas/CodeIgniter-Multi-Upload</a></p> <p>Your Form:</p> <pre><code>&lt;form method="post" enctype="multipart/formdata" action="/upload" id="upload_file"&gt; &lt;input class="text-input" id="files" name="files[]" type="file" multiple="" accept="image/*" /&gt; &lt;input type="submit" name="submit" id="submit" /&gt; &lt;/form&gt; </code></pre> <p>Your JS Script:</p> <pre><code>&lt;script src="/assets/js/jquery.js"&gt;&lt;/script&gt; &lt;script src="/assets/js/ajaxfileupload.js"&gt;&lt;/script&gt; &lt;script&gt; $(function() { $('#upload_file').submit(function(e) { e.preventDefault(); $.ajaxFileUpload({ url :'/upload', secureuri :false, fileElementId : 'files', dataType : 'json', data : { 'somedata' : 'somedata' }, success : function (data, status) { //do something here } }); }); }); &lt;/script&gt; </code></pre> <p>Your Codeigniter upload method :</p> <pre><code>public function upload() { $status = ""; $msg = ""; $file_element_name = 'files'; if ($status != "error") { $this-&gt;load-&gt;library('upload'); $this-&gt;upload-&gt;initialize(array( // takes an array of initialization options "upload_path" =&gt; "/mnt/httpd/htdocs/codeig/files/", // physical path where the files should be saved "overwrite" =&gt; TRUE, "encrypt_name" =&gt; TRUE, "remove_spaces" =&gt; TRUE, "allowed_types" =&gt; "gif|jpg|png|doc|txt", "max_size" =&gt; 30000, "xss_clean" =&gt; FALSE )); if (!$this-&gt;upload-&gt;do_multi_upload($file_element_name)) { $status = 'error'; $msg = $this-&gt;upload-&gt;display_errors('', ''); } else { $data = $this-&gt;upload-&gt;get_multi_upload_data(); if($data) { $status = "success"; $msg = "File successfully uploaded"; } else { $status = "error"; $msg = "Something went wrong when saving the file, please try again."; } } @unlink($_FILES[$file_element_name]); } echo json_encode(array('status' =&gt; $status, 'msg' =&gt; $msg)); } </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