Search code examples
phpcodeignitercodeigniter-2codeigniter-3

How to get file name encrypt file upload codeigniter in looping for


for ($img=0;$img<=5;$img++)
{
    if (!empty($_FILES['picture_add_'.$img]))
    {
        if ($this->upload->do_upload('picture_add_'.$img))
        {
            $uploaded = $this->upload->data();
            $data_picture_add = array(
                                    'filename'  => $uploaded['file_name'],
                                    'id'        => $last_id
                                    );
            $this->db->insert('db_picture_individual', $data_picture_add);
        }
    }
}

if I input 2 file picture or more, I just get one filename encrypted.

How to get all filename encrypted ?

this is the view :

<input name="picture_add_1" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_2" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_3" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_4" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_5" class="form-control" style="padding-top: 0;" type="file">

Solution

  • try to use config inside your loop statement.

            for ($i = 1; $i <= count($_FILES); $i++) {
               $config = array();
               $config['upload_path'] = './media/project_files';
               $config['allowed_types'] = '*';
               $config['max_size'] = '51200';
               $config['max_width'] = '5000';
               $config['max_height'] = '5000';
               $config['remove_spaces'] = TRUE;
               $config['encrypt_name'] = TRUE;
    
                $ups = $this->upload->do_upload("upload_file$i");
                $imgName[$i] = $this->upload->data();
            }