Codeigniter obtain image name for multiple files

42 views Asked by At

I have some code that i am using to upload multiple images i a form. I am uploading and renaming the images like this

//Obtain Picture

        $config['upload_path']          = './uploads/';
        $config['allowed_types']        = 'gif|jpg|png|pdf';
        $config['max_size']             = 5000;
        $config['max_width']            = 2000;
        $config['max_height']           = 2000;
        $rand_name = 'vehicles'.rand(321,8999).'_'.time();
        $config['file_name'] = $rand_name;
        $this->load->library('upload', $config);
        $this->upload->do_upload('logbook');
        $this->upload->do_upload('inrep');
        $this->upload->do_upload('insurance');
        $this->upload->do_upload('vp');
        $data = array('upload_data' => $this->upload->data());

the form names for the multiple uploads which are unrelated are as follows logbook,inrep,insurance and vp

The code above uploads the files and renames them but i would like to obtain the new names of the files given the form name of the fields.

Right now, the files are uploaded and renamed but i cant they are from which field name.

1

There are 1 answers

3
Cppi Khatri On BEST ANSWER

You can get new file name using

$this->upload->data();

This will return details of uploaded files. So you can do it like

$config['upload_path']          = './uploads/';
$config['allowed_types']        = 'gif|jpg|png|pdf';
$config['max_size']             = 5000;
$config['max_width']            = 2000;
$config['max_height']           = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);

$this->upload->do_upload('logbook');
$logbook = $this->upload->data();
$logbook_new_filename = $logbook['file_name'];

$this->upload->do_upload('inrep');
$inrep = $this->upload->data();
$inrep_new_filename = $inrep['file_name'];

$this->upload->do_upload('insurance');
$insurance= $this->upload->data();
$insurance_new_filename = $insurance['file_name'];

$this->upload->do_upload('vp');
$vp= $this->upload->data();
$vp_new_filename = $vp['file_name'];

I haven't tested it. But I use like this to get uploaded filename.Hope it will help.