title: CodeIgniter Upload Class - unique name for all files
body: <p>First - piece of codeigniter contoller where im uploading files:</p>
  
  <pre><code>        $files = $_FILES;
          $order_number = 5 //example
          $cpt = count($_FILES['userfile']['name']);
  
          $rand = md5(uniqid(rand(), true));
  
          for($i=0;$i&lt;$cpt;$i++)
          {
              if(!empty($files['userfile']['name'][$i]))
              {
                  $_FILES['userfile']['name']= $files['userfile']['name'][$i];
                  $_FILES['userfile']['type']= $files['userfile']['type'][$i];
                  $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
                  $_FILES['userfile']['error']= $files['userfile']['error'][$i];
                  $_FILES['userfile']['size']= $files['userfile']['size'][$i];    
  
                  $format=explode('.',$files['userfile']['name'][$i]);
                  $format=end($format);
  
                  $config_img['upload_path'] = './uploads/orders';
                  $config_img['allowed_types'] = 'jpg|png';
                  $config_img['file_name'] = $order_number.'_'.$rand.'.'.$format;
                  $config_img['max_size'] = '5120';
  (...)//some code that is not a problem
  $this-&gt;load-&gt;library('upload', $config_img);
  if($this-&gt;upload-&gt;do_upload())
  (...)
  </code></pre>
  
  <p>Okay. Gettin files to this point works but saving it up with another name is problem. 
  Fore expample i send file1.png and file2.jpg
  And im not gettin 5_123123123.png and 5_864192696219.jpg and thats the problem.
  Im gettin 2 files named same (only upload class add "1" before) but the biggest problem is that they have also same format. (.png in this example) my question is how can i get unique name here? Why its gettin for all files the same name?</p>