title: Image upload problem in crud operation CodeIgniter
body: <p>Hello everyone I need to upload image in uploads folder, In uploads folder it automatically create a username folder in that folder, I need to upload a image. For that I used mkdir to create a folder I'm getting folder name in username but in that folder image not uploading. Please help me to solve this I will share my code.</p>
  <p>Controller:</p>
  <pre><code>    public function insert()
      {
          if ($this-&gt;input-&gt;is_ajax_request()) {
              $this-&gt;form_validation-&gt;set_rules('id', 'ID', 'required');
              $this-&gt;form_validation-&gt;set_rules('username', 'UserName', 'required');
              $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required|valid_email');
              $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required');
              $this-&gt;form_validation-&gt;set_rules('level', 'Level', 'required');
              $this-&gt;form_validation-&gt;set_rules('salary', 'Salary', 'required');
              $this-&gt;form_validation-&gt;set_rules('bonus', 'Bonus', 'required');
              if ($this-&gt;form_validation-&gt;run() == FALSE) {
                  $data = array('responce' =&gt; 'error', 'message' =&gt; validation_errors());
              } else {
                  $config['upload_path'] = &quot;../assets/uploads/&quot;;
                  $config['allowed_types'] = 'gif|jpg|png';
                  $config['max_size']     = '1000';
                  $config['file_name'] =$this-&gt;input-&gt;post('username');
  
                  $this-&gt;load-&gt;library('upload', $config);
                  if (!$this-&gt;upload-&gt;do_upload(&quot;img&quot;)) {
                      $data = array('responce' =&gt; &quot;error&quot;, 'message' =&gt; $this-&gt;upload-&gt;display_errors());
                  } else {
                      $ajax_data = array(
                          'id'=&gt;$this-&gt;input-&gt;post('id'),
                          'username'=&gt;$this-&gt;input-&gt;post('username'),
                          'email'=&gt;$this-&gt;input-&gt;post('email'),
                          'password'=&gt;md5($this-&gt;input-&gt;post('password')),
                          'level'=&gt;$this-&gt;input-&gt;post('level')
                      );
                      $ajax_data2 =array(
                          'id'=&gt;$this-&gt;input-&gt;post('id'),
                          'salary'=&gt;$this-&gt;input-&gt;post('salary'),
                          'bonus'=&gt;$this-&gt;input-&gt;post('bonus'),
                          'img'=&gt;$this-&gt;input-&gt;post()
                      );
                      $ajax_data2['img'] = mkdir($this-&gt;upload-&gt;data('file_name'),0777,true);
  
                      if ($this-&gt;login_model-&gt;insert_entry($ajax_data,$ajax_data2)) {
                          $data = array('responce' =&gt; &quot;success&quot;, 'message' =&gt; &quot;Data added successfully&quot;);
                      } else {
                          $data = array('responce' =&gt; &quot;error&quot;, 'message' =&gt; &quot;Failed to add data&quot;);
                      }
                  }
                  echo json_encode($data);
              }
          } else {
              echo &quot;No direct script access allowed&quot;;
          }
      }
  </code></pre>
  <p>ajax file :</p>
  <pre><code>$(document).on(&quot;click&quot;, &quot;#add&quot;, function(e) {
  e.preventDefault();
  
  var id = $(&quot;#id&quot;).val();
  var username = $(&quot;#username&quot;).val();
  var email = $(&quot;#email&quot;).val();
  var password = $(&quot;#password&quot;).val();
  var level = $(&quot;#level&quot;).val();
  var salary = $(&quot;#salary&quot;).val();
  var bonus = $(&quot;#bonus&quot;).val();
  var img = $(&quot;#img&quot;)[0].files[0];
  
  if (id == &quot;&quot; || username == &quot;&quot; || email == &quot;&quot; || password == &quot;&quot; ||level == &quot;&quot;||salary == &quot;&quot;||bonus == &quot;&quot;||img == &quot;&quot;) {
    alert(&quot;All field are required&quot;);
  } else {
    var fd = new FormData();
  
    fd.append(&quot;id&quot;, id);
    fd.append(&quot;username&quot;, username);
    fd.append(&quot;email&quot;, email);
    fd.append(&quot;password&quot;, password);
    fd.append(&quot;level&quot;, level);
    fd.append(&quot;salary&quot;, salary);
    fd.append(&quot;bonus&quot;, bonus);
    fd.append(&quot;img&quot;, img);
    $.ajax({
        type: &quot;post&quot;,
        url: &quot;&lt;?php echo base_url(); ?&gt;index.php/Admin/insert&quot;,
        data: fd,
        processData: false,
        contentType: false,
        dataType: &quot;json&quot;,
        success: function(response) {
            if (response.responce == &quot;success&quot;) {
              Swal.fire({
                    position: 'center',
                    icon: 'success',
                    title: 'Your work has been saved',
                    showConfirmButton: false,
                    timer: 1500
                  })
                $(&quot;#frm&quot;)[0].reset();
            } else {
                toastr['error'](response.message);
            }
        },
    });
  }
  });
  </code></pre>
  <p>Please check my code and help me to solve this problem. Thank you all</p>