silvia zulinka silvia zulinka - 1 year ago 111
PHP Question

How to insert multiple file upload encrypted filename with multiple input in codeigniter?

How to insert multiple file upload encrypted filename with multiple input in codeigniter ?

I have multiple input file in my view like this:

<input name="picture_1" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_2" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_3" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_4" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_5" class="form-control" style="padding-top: 0;" type="file">


How to make filename encrypted when file uploaded and file will upload based on how many I input file.

for example:

if I input 3 file picture, file data will upload 3 file in directory, and name will stored to database.

Answer Source

place this code to your controller:

$config['upload_path']      = './assets/img/packet/';
$config['allowed_types']    = 'jpg|png|gif|jpeg';
$config['max_size']         = 125000; // 1 GB
$config['encrypt_name']     = TRUE;
$this->load->library('upload', $config);
$this->upload->initialize($config);

for ($img=0;$img<=5;$img++)
{
   if (!empty($_FILES['picture_'.$img]))
   {
       if ($this->upload->do_upload('picture_'.$img))
       {
           $uploaded = $this->upload->data();
           $data_picture = array('filename'  => $uploaded['file_name']);
           $this->db->insert('db_picture', $data_picture);
       }
   }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download