我想上传多张图片,HTML FORM
但只提交最后一张上传的图片,请任何能解决这个问题的人
这是我的控制器
if($_FILES['image']['name'] != "")
{
$data['image'] = $this->MUtils->doUpload('image',270,65,false);
}
if($_FILES['adv_image1']['name']!= "")
{
$data['adv_image1'] = $this->MUtils->doUpload('adv_image1',340,130,false);
}
if($_FILES['adv_image2']['name']!= "")
{
$data['adv_image2'] = $this->MUtils->doUpload('adv_image2',860,100,false);
}
型号是
if($data['image']!="" ){
$arr=array('image' => $data['image']);
}
if($data['adv_image1']!=""){
$arr=array('adv_image1' => $data['adv_image1']);
}
if($data['adv_image2']!=""){
$arr=array('adv_image2' => $data['adv_image2']);
}
if($data['adv_image3']!=""){
$arr['adv_image3'] = $data['adv_image3'];
}
$this->db->where('id',$data['listid']);
$this->db->update('list', $arr);
return 1;
doUpload 功能在这里
//Upload file and return url
function doUpload($field, $width, $height, $resize=false)
{
//Configure upload.
$this->upload->initialize(array(
"upload_path" => "../uploads/",
"allowed_types" => "gif|jpg|png",
));
//Perform upload.
if($this->upload->do_upload($field)){
$fileData = $this->upload->data();
if ($resize == true)
{
$width = $fileData['image_width'];
$height = $fileData['image_height'];
}
$img_cfg_thumb['image_library'] = 'gd2';
$img_cfg_thumb['source_image'] = "../uploads/" . $fileData['raw_name'] . $fileData['file_ext'];
$img_cfg_thumb['maintain_ratio'] = FALSE;
$img_cfg_thumb['new_image'] = "../uploads/" . $fileData['raw_name'] . $fileData['file_ext'];
$img_cfg_thumb['width'] = $width;
$img_cfg_thumb['height'] = $height;
$img_cfg_thumb['quality'] = 90;
$this->load->library('image_lib');
$this->image_lib->initialize($img_cfg_thumb);
$this->image_lib->resize();
return $fileData['raw_name'] . $fileData['file_ext'];
}
else
{
return "";
}
}
请注意,这是有效的,但是从三张图片中,只有最后一张是在提交时上传的