CodeIgniter Forums
problem with insert upload file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: problem with insert upload file (/thread-66633.html)



problem with insert upload file - Abdoul Aziz - 11-14-2016

i have problem with my implode function when i try to insert just one line with come it always store many lines need helps this is my code 


$config["upload_path"]   = $this->upload_path;
$config["allowed_types"] = "jpg|jpeg|png|gif";
$config['file_name'] = $_FILES['file']['name'];


$files = [];
$ids = '';
foreach ($_FILES as $key => $value) {
if (!empty($value['name'])) {
   $this->load->library('upload', $config);
                if (!$this->upload->do_upload($key)) {
                    echo "failed to upload file(s)";
                }
                else{
$fileData = $this->upload->data();
//$files[$i] = $this->upload->data();
//$file [] = $files[$i]['file_name'];
$files[] = $fileData['file_name'];
//$file = $dir_path . $files[$i]['file_name'];
//++$i;
}
}
}
if(is_array($files)){
$ids = implode(',', $files);
$this->db->set('image', implode(', ',$files));
$this->db->insert('annonce');
}