我正在使用codeigniter上传库上传多张图片。大多数情况下,它工作正常,但在某些情况下,图像不上传。
功能:
function do_upload_img()
{
if(isset($_FILES['portfolioimg']['size']) != 0){
$name_array = array();
$files = $_FILES;
$cpt = count($_FILES['portfolioimg']['name']);
// $config['source_image'] = ''; //get original image
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './assets/img/watermark.png';
$config['quality'] = 50;
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$this->load->library('image_lib', $config);
for($i=0; $i<=$cpt-1; $i++)
{
$_FILES['userfile']['name']= $files['portfolioimg']['name'][$i];
$_FILES['userfile']['type']= $files['portfolioimg']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['portfolioimg']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['portfolioimg']['error'][$i];
$_FILES['userfile']['size']= $files['portfolioimg']['size'][$i];
$imgnam = rand(10,1000000).time();
$ext = pathinfo($files['portfolioimg']['name'][$i], PATHINFO_EXTENSION);
if($this->upload->initialize($this->set_upload_options($imgnam))){
$data = $this->upload->do_upload();
$config['source_image'] = './assets/portfolio_img/' . 'Rookie_'.$imgnam.'.'.$ext;
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$name_array[] = $this->upload->data('file_name');
$this->create_thumbnail('./assets/portfolio_img/',$imgnam,$ext);
}else{
$this->session->set_flashdata('falsemsg','Only jpg, jpeg, png files are allowed to be uploaded.');
}
}
return $name_array;
}else{
return false;
}
}
private function set_upload_options($imgnam)
{
//upload an image options
$config = array();
$config['upload_path'] = './assets/portfolio_img/';
$config['allowed_types'] = 'jpeg|jpg|png|JPEG|JPG|PNG';
$config['max_size'] = '0';
$config['overwrite'] = true;
$config['file_name'] = 'Rookie_'.$imgnam;
return $config;
}
这是我用来上传图片的函数。我不知道为什么它有时不工作。所以请帮助我找出我的代码中的错误。提前感谢。
2条答案
按热度按时间i86rm4rw1#
0vvn1miw2#
控制器:
查看: