我设法上传并调整了多张图片的大小,一切都很好 然后,如果没有选择上传图像,我想显示错误 我把一个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');
}
}
}
答案 0 :(得分:0)
您正在运行$this->upload->do_upload()
两次,因为您的foreach()
会运行,然后您的if/else
语句会运行。
您需要将if/else
放入foreach
循环中。您应该注意不要只是复制/粘贴它,但要确保每个图像只运行$this->upload->do_upload()
一次。