title: How to upload image in CodeIgniter?
body: <p>In view</p>
  
  <pre><code> &lt;?php echo form_open_multipart('welcome/do_upload');?&gt;
   &lt;input type="file" name="userfile" size="20" /&gt;
  </code></pre>
  
  <p>In controler</p>
  
  <pre><code>function do_upload()
  {
      $config['upload_path'] = './uploads/';
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size'] = '100';
      $config['max_width']  = '1024';
      $config['max_height']  = '768';
      $config['overwrite'] = TRUE;
      $config['encrypt_name'] = FALSE;
      $config['remove_spaces'] = TRUE;
      if ( ! is_dir($config['upload_path']) ) die("THE UPLOAD DIRECTORY DOES NOT EXIST");
      $this-&gt;load-&gt;library('upload', $config);
      if ( ! $this-&gt;upload-&gt;do_upload('userfile')) {
          echo 'error';
      } else {
  
          return array('upload_data' =&gt; $this-&gt;upload-&gt;data());
      }
  }
  </code></pre>
  
  <p>And I call this function like this</p>
  
  <pre><code> $this-&gt;data['data'] = $this-&gt;do_upload();
  </code></pre>
  
  <p>and view this image:</p>
  
  <pre><code>&lt;ul&gt;
  &lt;?php foreach ($data['upload_data'] as $item =&gt; $value):?&gt;
  &lt;li&gt;&lt;?php echo $item;?&gt;: &lt;?php echo $value;?&gt;&lt;/li&gt;
  &lt;?php endforeach; ?&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I don't know what's the error.</p>