2016-10-22 217 views
0

我一直在嘗試使用codeigniter文件上傳庫上傳多個圖像。一切正常,除非它不保存目錄中的圖像, 我有檢查權限一切都很完美。我也試過改變軟件包,但仍面臨同樣的問題。Codeigniter文件上傳錯誤

這是我上傳的代碼。

$count = count($_FILES['upload_' . $increment]['size']); 

    for ($s = 0; $s <= $count-1; $s++) { 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
    $config['max_size']  = '10000'; 
    $config['max_width']  = '2048'; 
    $config['max_height'] = '1152'; 

    $image = $config['file_name'] = $c_id . '-' . $s . '.jpg'; 

    $this->load->library('upload', $config); 
    $this->upload->initialize($config); 
    $this->upload->do_upload(); 

    $data = $this->upload->data(); 
    $data = array('c_id' => $c_id, 'image'=> $image); 

    $this->db->insert('images', $data); 
    } 

    $increment++; 
+0

也許這將工作'$配置[「upload_path」] =「./assets/uploads /」;' – devpro

+0

我已經確定比刪除點的父目錄 –

+0

上傳文件夾路徑 – devpro

回答

0

您是否使用html表單操作提交數據?

如果是的話,請加enctype="multipart/form-data"到表單標籤爲:

<form action="your action url" method="post" enctype="multipart/form-data"> 
0

試試這個 Downlaod this Codeigniter Library and put this file under application/libraries

控制器

if ($_FILES) { 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size']  = '200'; 
    $config['max_width']  = '1024'; 
    $config['max_height'] = '768'; 
    $this->load->library('upload'); 
    $this->upload->initialize($config); 
    if (!$this->upload->do_multi_upload("file")) { 
     $data['errors'] = ($this->upload->display_errors()); 
    } else { 
     $images = ($this->upload->get_multi_upload_data()); 
     for ($i = 0; $i < count($images); $i++) { 
     $this->user_model->addUserImage($images[$i]); 
     } 
    } 

型號

public function addUserImage($image) 
{ 
    $image_data=array(
    'name'=>$image['file_name'] 
); 
    $this->db->insert('user_images',$image_data); 
    return true; 
} 

讓我如果在這裏的任何查詢