title: Image upload to specific folder in codeigniter
body: <p>I've been trying to upload images to specific folder my scenario is I've upload controller in which I've do_upload function</p>
  
  <pre><code>   public function do_upload($field_name) {
          $field_name = 'image_title';
          $page_id = $this-&gt;input-&gt;post('page_id');
          $config = array(
              'allowed_types' =&gt; '*',
              'max_size' =&gt; '1024',
              'max_width' =&gt; '1024',
              'max_height' =&gt; '768',
              'upload_path' =&gt; './uploads/'. $page_id
          );
          $this-&gt;load-&gt;library('upload');
          $this-&gt;upload-&gt;initialize($config);
  if (!is_dir('uploads'))
      {
          mkdir('./uploads/', 0777, true);
      }
  $dir_exist = true; // flag for checking the directory exist or not
  if (!is_dir('uploads/' . $page_id))
      {
          mkdir('./uploads/' . $page_id, 0777, true);
          $dir_exist = false; // dir not exist
      }
      else{
      }
          if (!$this-&gt;upload-&gt;do_upload($field_name)) {
              if(!$dir_exist)
            rmdir('./uploads/' . $page_id);
              $this-&gt;data['error'] = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
          } else {
  
              $fInfo = $this-&gt;upload-&gt;data($field_name);
              $this-&gt;_createThumbnail($fInfo['file_name']);
              return $fInfo;
          }
   }
   /**********************************************************************************************/
      function _createThumbnail($filename)
  
      {
  
          $config['image_library']    = "gd2";      
          $config['source_image']     = "uploads/" .$filename;      
          $config['create_thumb']     = TRUE;      
          $config['maintain_ratio']   = TRUE;      
          $config['width'] = "80";      
          $config['height'] = "80";
  
          $this-&gt;load-&gt;library('image_lib',$config);
  
          if(!$this-&gt;image_lib-&gt;resize())
  
          {
  
              echo $this-&gt;image_lib-&gt;display_errors();
  
          } 
  </code></pre>
  
  <p>I've index view file given as</p>
  
  <pre><code>&lt;section&gt;
  &lt;?php echo validation_errors(); ?&gt;
  &lt;?php //echo form_open_multipart('admin/upload/index/' . ((isset($page-&gt;id)) ? $page-&gt;id : '' ));   ?&gt; 
  &lt;?php echo form_open_multipart('admin/upload/index/'); ?&gt; 
  &lt;tr&gt;
      &lt;td&gt;&lt;h3&gt;Upload Images&lt;/h3&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;table class="table table-striped"&gt;    
      &lt;tr&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Image Name&lt;/th&gt;
              &lt;th&gt;View&lt;/th&gt;
              &lt;th&gt;Delete&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;?php if (count($images)): foreach ($images as $image): ?&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;?php echo anchor('admin/upload/index/' . $image-&gt;id, $image-&gt;image_title); ?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo btn_edit('admin/upload/index/' . $image-&gt;id); ?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo btn_delete('admin/upload/index/' . $image-&gt;id); ?&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;?php endforeach; ?&gt;
          &lt;?php else: ?&gt;
              &lt;tr&gt;
                  &lt;td colspan="3"&gt;There is no Image to display&lt;/td&gt;
              &lt;/tr&gt;
          &lt;?php endif; ?&gt;
          &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/section&gt;
  &lt;section&gt;
  &lt;table class="table table-striped"&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;h5&gt;Select Page&lt;/h5&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo form_dropdown('page_id', $get_with_images, $this-&gt;input-&gt;post('page_id')); ?&gt;&lt;/td&gt;
  
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;h5&gt;Select Image&lt;/h5&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;?php echo form_upload('image_title', set_value('image_title', $image-&gt;image_title)); ?&gt;
              &lt;/td&gt; 
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;?php echo form_submit('submit', 'Upload', 'class="btn btn-success"'); ?&gt;&lt;/td&gt;
  
          &lt;/tr&gt;
  
  &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;?php echo form_close(); ?&gt;
  &lt;/section&gt;
  </code></pre>
  
  <p>dropdown is populating from page controller what actually I needed is I want to upload image to the page selected from dropdown for example if "Contact" page is selected from dropdown I want to upload my image to "Contact" page and on the backend I want to create directory with the same name as selected in dropdown in my case I want "uploads/home/abc.jpg" and same for the other pages please advice the basic idea I will modify it with my own</p>