[英]Uploading multiple image with different input file in Codeigniter
So I have four input files in my forms and I send it on my global $_FILES with the following indices: front,rear,right and left. 因此,我的表单中有四个输入文件,并将其通过以下索引在全局$ _FILES上发送:前,后,右和左。
I want to upload these using codeigniter image class library. 我想使用codeigniter图片类库上传这些内容。 This is my code:
这是我的代码:
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 ';
}
}
}
}
However it gives me the following error: 但是,它给了我以下错误:
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您没有选择要上传的文件。
右不存在左不存在
I think I did not correctly specified which resource on the $_FILES should be uploaded. 我想我没有正确指定$ _FILES上的哪个资源应该上传。
Your response would be greatly appreciated. 您的答复将不胜感激。
Thanks 谢谢
我通过在codeigniter的do_upload()中提供索引来解决它
$this->_CI->upload->do_upload($tag);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.