0

我想上传多张图片,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 "";
        }
    }

请注意,这是有效的,但是从三张图片中,只有最后一张是在提交时上传的

4

2 回答 2

1

In your model change following lines:

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=array('adv_image3' => $data['adv_image3']);
}

To these lines:

if($data['image']!="" ){
    $arr['image'] = $data['image'];
}
if($data['adv_image1']!=""){
    $arr['adv_image1'] = $data['adv_image1'];
}
if($data['adv_image2']!=""){
    $arr['adv_image2'] = $data['adv_image2'];
}
if($data['adv_image3']!=""){
    $arr['adv_image3'] = $data['adv_image3'];
}
于 2014-05-21T14:24:42.397 回答
-1

每次都需要清除配置和库。

在函数开始时尝试以下代码:

unset($config)
$this->upload->clear();

希望这可以帮助

于 2014-05-21T13:22:14.477 回答