Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you use codeigniter's file uploader class... and call <code>$this-&gt;upload-&gt;do_upload();</code> in a conditional statement ahd check if its true.</p> <pre><code>&lt;?php if ( ! $this-&gt;upload-&gt;do_upload()){ $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors()); $this-&gt;load-&gt;view('upload_form', $error); } else{ $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data()); $this-&gt;load-&gt;view('upload_success', $data); } </code></pre> <p><strong>The user_guide explains this in detail:</strong> <a href="http://codeigniter.com/user_guide/libraries/file_uploading.html" rel="nofollow noreferrer">http://codeigniter.com/user_guide/libraries/file_uploading.html</a></p> <p>However, if you are dead set on checking whether a file has been "uploaded" aka.. submitted BEFORE you call this class (not sure why you would). You can access PHPs <code>$_FILES</code> super global.. and use a conditional to check if size is > 0.</p> <p><a href="http://www.php.net/manual/en/reserved.variables.files.php" rel="nofollow noreferrer">http://www.php.net/manual/en/reserved.variables.files.php</a></p> <p><strong>Update 2:</strong> This is actual working code, i use it on an avatar uploader myself using CI 2.1</p> <pre><code>&lt;?php //Just in case you decide to use multiple file uploads for some reason.. //if not, take the code within the foreach statement foreach($_FILES as $files =&gt; $filesValue){ if (!empty($filesValue['name'])){ if ( ! $this-&gt;upload-&gt;do_upload()){ $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors()); $this-&gt;load-&gt;view('upload_form', $error); }else{ $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data()); $this-&gt;load-&gt;view('upload_success', $data); } }//nothing chosen, dont run. }//end foreach </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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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