title: How to delete a file from folder by using codeigniter
body: <p>While uploading csv file iam saving that file in uploads folder if the file uplaoded successfully into database or  not uploaded then also it should be deleted automatically from that folder.Can any one help me regarding this.</p>
  
  <pre><code>$data['error'] = '';      
  $config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'csv';
  $config['max_size'] = '10000';
  $this-&gt;load-&gt;library('upload', $config);
  
  if (!$this-&gt;upload-&gt;do_upload()) {
    $data['error'] = $this-&gt;upload-&gt;display_errors();
  } 
  else {
    $file_data = $this-&gt;upload-&gt;data();
    $file_path =  './uploads/'.$file_data['file_name'];
    $csv_array = $this-&gt;csvimport-&gt;get_array($file_path,'',FALSE,0,3,0,$cformat);   
  
    if ($csv_array) {
      $successflag=true;
  
      foreach ($csv_array as $row) {
        $order = array(                  
          'department'=&gt;$row['Department'],
          'gender'=&gt;$row['Gender'],             
        );    
        $query = $this-&gt;db-&gt;query("select count(*) cnt from order_master where order_id='{$order['order_id']}' ");
        $row = $query-&gt;first_row();
  
        if(trim($order['order_id'] )!="" &amp;&amp; $row-&gt;cnt==0 ) {
          $this-&gt;masterorder_model-&gt;order($order);             
        }
        else if (  $row-&gt;cnt&gt;0) {
          $successflag=false;
          $this-&gt;flash-&gt;success("&lt;h5&gt;&lt;font color='red'&gt;Found Duplicate Order Id'{$order['order_id']}' for order name '$oname'&lt;/font&gt;&lt;/h5&gt;");
          break;
        }    
      }
  
      if(!$successflag) {
        $this-&gt;db-&gt;trans_rollback();     
      }
      else {
        $this-&gt;db-&gt;trans_commit();
        $this-&gt;flash-&gt;success('&lt;h5&gt;Csv Data Imported Successfully.&lt;/h5&gt;');
      }
      redirect(base_url().'masterorder/index');
    }
    else {
      $this-&gt;flash-&gt;success('&lt;h5&gt;&lt;font color="red"&gt;Invalid file format.&lt;/font&gt;&lt;/h5&gt;');
      redirect(base_url().'masterorder/index');
    }
  }
  }
  </code></pre>