0
這裏我試圖插入多個圖像到數據庫中,但它們沒有被插入。圖像正確上傳到文件夾,但不知道爲什麼它沒有進入數據庫。 這裏是我的圖片上傳功能爲什麼多次上傳沒有被插入到數據庫中
public function multiple_upload_files($path)
{
$images = array();
if(!empty($_FILES['files']['name'])){
$filesCount = count($_FILES['files']['name']);
for($i = 0; $i < $filesCount; $i++){
$_FILES['file']['name'] = $_FILES['files']['name'][$i];
$_FILES['file']['type'] = $_FILES['files']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['files']['error'][$i];
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
$config['upload_path']= './uploads/'.$path.'/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size']= '2000';
$config['max_width'] = '4000';
$config['max_height'] = '6500';
$config['file_name']='upld-file'.time();
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload("file")) {
$images[] = $this->upload->data();
}
else {
redirect('admin/view-product');
}
}
return $images;
}
這裏是我的插入代碼
$path='products';
if($this->multiple_upload_files($path))
{
$img=implode(',',$images);
$data = array('product_name' => $this->input->post('product_name'),'image'=>$img);
$status = $this->Admin_model->db_insert($table='products',$data);
if($status)
{
$this->session->set_flashdata('message','Product added Successfully');
}
else
{
$this->session->set_flashdata('message','Insertion failed');
}
的問題是圖像上傳到上傳文件夾,而不是數據庫。
[使用CodeIgniter多圖片上傳]的可能的複製(https://stackoverflow.com/questions/40778683/multiple-image-upload-with-codeigniter) –