我以某种方式设法上传并调整了多张图片的大小,一切都很好。
然后,如果没有选择要上传的图像,我想显示错误。
我放了一个 if 语句来加载错误,但这会造成严重破坏。
每次我选择图像并上传时,最后一张都会被复制,没有调整大小。
同样,如果我删除 if else,那很好。
感谢您的任何帮助和您的时间。
function do_upload(){
$path = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value){
for($n=0; $n<=$count-1; $n++) {
$_FILES['userfile']['name']=$value['name'][$n];
$_FILES['userfile']['type'] = $value['type'][$n];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$n];
$_FILES['userfile']['error'] = $value['error'][$n];
$_FILES['userfile']['size'] = $value['size'][$n];
$config['upload_path'] = './images';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$path[] = $data['full_path'];
}
if(!$this->upload->do_upload()){
$error = array('error' => $this->upload->display_errors());
$this->load->view('view_dashboard_error_car', $error);
}
else{
$this->load->library('image_lib');
foreach($path as $p=>$ath){
$config1 = array(
'source_image' => $ath,
'new_image' => './images',
'maintain_ration' => true,
'overwrite' => true,
'width' => 600,
'height' => 400
);
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$this->image_lib->clear();
}
$this->load->view('view_dashboard_success_car');
}
}
}