php - Rename multiple file upload codeigniter -


i want rename files during uploading process. i'm uploading 3 files @ single time. frontend code

<form> <input type="file" class="form-control" name="photo_1"> <input type="file" class="form-control" name="pan_1"> <input type="file" class="form-control" name="add_1"> </form> 

my code in controller following

function upload(){     $this->upload_file('photo_1');      $this->upload_file('pan_1');      $this->upload_file('add_1'); } function upload_file($field_name)     {          //$ext = substr( strrchr($_files[$field_name]['name'], '.'), 1);         //$new_name = $types.'_'.$numb.'_dev_.'.$ext;         $config['file_name']            = $_files[$field_name]['name'];         $config['upload_path']          = './uploads/';         $config['allowed_types']        = 'jpeg|jpg|png';        // $config['max_size']             = 100;          $this->load->library('upload', $config);          if ( ! $this->upload->do_upload($field_name))         {             return array('error' => $this->upload->display_errors());          }         else         {             $data = array('upload_data' => $this->upload->data());          }     } 

but i' getting same name each file increment. like photo_1, photo_11, photo_12. want file name photo_sometext_1

any appreciated

problem here $config['file_name'] = $_files[$field_name]['name'];. need pass desired file name.

or

good approach create encrypt_name each file. way codeigniter create random name each file uploaded.

see https://www.codeigniter.com/userguide3/libraries/file_uploading.html#preferences document see available options.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -