Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter unable to load upload library when called in model
    text
    copied!<p>Im having trouble with the $this->load->library('upload'); if i call it in the controller it works just fine but when i put it inside a model it gives me an error " Call to a member function do_upload() on a non-object"</p> <p>Here's my upload code. </p> <pre><code>function upload_file_model(){ if(isset($_FILES['upPhoto'])){ $upMsg = ""; $uploadPath; $uploadDirectory; $this-&gt;uploadPath = realpath(APPPATH . DIRECTORY_SEPARATOR . "root"); $this-&gt;uploadDirectory = $this-&gt;input-&gt;post('txt_current_directory'); $this-&gt;uploadDirectory = explode("/", $this-&gt;uploadDirectory); $this-&gt;uploadDirectory = implode(DIRECTORY_SEPARATOR, $this-&gt;uploadDirectory); $this-&gt;upload = $this-&gt;uploadPath . DIRECTORY_SEPARATOR . $this-&gt;uploadDirectory; for($i = 0;$i&lt;count($_FILES['upPhoto']['name']);$i++){ $_FILES['userfile']['name'] = $_FILES['upPhoto']['name'][$i]; $_FILES['userfile']['type'] = $_FILES['upPhoto']['type'][$i]; $_FILES['userfile']['tmp_name'] = $_FILES['upPhoto']['tmp_name'][$i]; $_FILES['userfile']['error'] = $_FILES['upPhoto']['error'][$i]; $_FILES['userfile']['size'] = $_FILES['upPhoto']['size'][$i]; $config = array( 'upload_path' =&gt; $this-&gt;upload, 'allowed_types' =&gt; 'gif|jpg|png|jpeg|doc|csv', 'max_size' =&gt; '10000', 'max_width' =&gt; '10000', 'max_height' =&gt; '10000', 'overwrite' =&gt; false, 'file_name' =&gt; 'test_' + $i ); $this-&gt;load-&gt;library('upload', $config); if($this-&gt;upload-&gt;do_upload()){ $this-&gt;upMsg .= $_FILES['upPhoto']['name'][$i] . " Uploaded. &lt;br&gt;"; }else{ $this-&gt;upMsg .= $_FILES['upPhoto']['name'][$i] . " was not Uploaded. &lt;br&gt; . ERROR : " . $this-&gt;upload-&gt;display_errors(); } } // echo $this-&gt;upMsg; $this-&gt;status = TRUE; $this-&gt;msg = $this-&gt;upMsg; }else{ // echo "FALSE"; $this-&gt;status = FALSE; $this-&gt;msg = "ERROR : You did not select a file to upload."; } return $this-&gt;respond(); } </code></pre> <p>Most of the code comes from this link <a href="https://stackoverflow.com/questions/1908247/codeigniter-multiple-file-upload">Codeigniter multiple file upload messes file extension</a> ~by phpx i just modified some of it. </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