0
因此,我的表單中有四個輸入文件,並使用以下索引將其發送到全局$ _FILES上:前,後,右和左。在Codeigniter中使用不同的輸入文件上傳多個圖像
我想上傳這些使用codeigniter圖像類庫。這是我的代碼:
public function upload_to_temp($id, $folder, $tags){
$path = realpath(APPPATH . '../public/resources/temps/' . $folder);
//makes a directory
mkdir($path . '/' . $id, 0700);
//navigate to the newly created path
$path = realpath(APPPATH . '../public/resources/temps/' . $folder . '/' . $id);
if(isset($tags)){
//use these tags to check the files present on submission
foreach($tags as $tag){
if(array_key_exists($tag,$_FILES)){
if(!empty($_FILES) && $_FILES[$tag]["name"] != "" && isset($_FILES[$tag]["name"])){
$config = array (
'source_image' => $_FILES[$tag]["name"],
'image_library' => 'gd',
'upload_path' => $path,
'file_name' => $id . '_' . $tag . '.jpg',
'allowed_types' => 'png|jpg|jpeg',
'overwrite' => TRUE,
'max_size' => '2000',
);
$this->_CI->upload->initialize($config);
if(!$this->_CI->upload->do_upload()){
echo 'Error creating image. ';
echo $this->_CI->upload->display_errors();
}else{
echo 'Success saving to temp folder';
}
//kapag failed
if(!$this->_CI->upload->do_upload()){
echo 'Error creating image.';
echo $this->_CI->upload->display_errors();
}else{
//now, the $path will become our resource path for copying and creating thumbnails.
$resouce_path = $config['upload_path'] . '/' . $config['file_name'];
$this->img_create_thumb($resouce_path, $folder);
}
}else{
//Hindi na dapat marating to!
echo $tag . ' not present ';
}
}else{
//use default pictures
echo $tag . ' not present ';
}
}
}
}
但是它給了我下面的錯誤:
Error creating image.
You did not select a file to upload.
Error creating image.You did not select a file to upload.
You did not select a file to upload.
Error creating image.You did not select a file to upload.
Error creating image.You did not select a file to upload.
You did not select a file to upload.
right not present left not present
我覺得我沒有正確指定哪些資源上的$ _FILES應該被上傳。
您的迴應將不勝感激。
感謝
你問了一個問題,自己回答這個問題嗎?如果你看一下CI或搜索文檔您的問題,您會找到很多答案。 –