【问题标题】:Updating two image in Codeigniter在 Codeigniter 中更新两个图像
【发布时间】:2018-10-29 18:11:55
【问题描述】:

最近我在一次更新两个图像时发现了一些错误。我在第一张图片之前使用if (!empty($_FILES['ngo_logo']['name'])),在第二张图片之前使用elseif (!empty($_FILES['ngo_license_pic']['name']))

这是我的完整控制器代码:

function editProfile(){

    $ngo_id = $this->profile_model->editNgoProfile();

        /************* File Upload ************/
  if (!empty($_FILES['ngo_logo']['name'])) {


        $config['upload_path'] = './assets/uploads/ngo_logo/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|docx|zip|xls';
        $config['overwrite'] = true;
        $config['remove_spaces']=true;
        $config['max_size']='10600';// in KB

        $this->load->library('upload', $config);


        $filetype = $_FILES['ngo_logo']['type'];
        $file_name = $_FILES['ngo_logo']['name'];

        if($filetype == "image/jpg")
                $file_type='jpg';
            else if ($filetype == "image/jpeg")
                $file_type='jpeg';
            else if ($filetype == "image/gif")
                $file_type='gif';
            else if($filetype == "image/jpeg")
                $file_type='jpg';

            else if($filetype == "image/pjpeg")
                $file_type='pjpeg';
            else if($filetype ==  "image/png")
                $file_type='png';

        $_FILES['ngo_logo']['name']=$ngo_id.'.'.$file_type;

        $this->upload->do_upload('ngo_logo');


        $up_dtat = array('ngo_logo' => $_FILES['ngo_logo']['name']);
        $this->db->where('ngo_id',$ngo_id);
        $this->db->update('tbl_ngo_users',$up_dtat);

   }


  elseif (!empty($_FILES['ngo_license_pic']['name'])) {


        $config['upload_path'] = './assets/uploads/ngo_license_pic/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|docx|zip|xls';
        $config['overwrite'] = true;
        $config['remove_spaces']=true;
        $config['max_size']='10600';// in KB

        $this->load->library('upload', $config);


        $filetype = $_FILES['ngo_license_pic']['type'];
        $file_name = $_FILES['ngo_license_pic']['name'];

        if($filetype == "image/jpg")
                $file_type='jpg';
            else if ($filetype == "image/jpeg")
                $file_type='jpeg';
            else if ($filetype == "image/gif")
                $file_type='gif';
            else if($filetype == "image/jpeg")
                $file_type='jpg';

            else if($filetype == "image/pjpeg")
                $file_type='pjpeg';
            else if($filetype ==  "image/png")
                $file_type='png';

        $_FILES['ngo_license_pic']['name']=$ngo_id.'.'.$file_type;

        $this->upload->do_upload('ngo_license_pic');


        $up_dtat = array('ngo_license_pic' => $_FILES['ngo_license_pic']['name']);
        $this->db->where('ngo_id',$ngo_id);
        $this->db->update('tbl_ngo_users',$up_dtat);

 }
    redirect('NGO_Profile');

}

我的问题是只有第一张图片会更新,而另一张不会更新。
--> 如果我只上传一张图片,那么它会更新并
--> 如果我只上传第一张图片,那么第一张图片更新
--> 以后如果我只上传第二张图片,那么第二张图片将只更新...

我需要正确的解决方案,实际上不一次更新两个图像的主要原因是什么。

【问题讨论】:

    标签: php codeigniter image-uploading


    【解决方案1】:

    elseif (!empty($_FILES['ngo_license_pic']['name'])) { 更改为if(...)

    elseifs 仅在 A. 第一个 if 条件为假 B. elseif 条件为真时触发。

    【讨论】:

    • 它的工作。但无法将照片上传到其他文件夹
    • 文件夹必须存在。 Ci 不会为你创建它
    • 提出一个包含所有细节的新问题是我现在能给你的最好建议
    • 好的,但是我在提出新问题时遇到了一些问题:它说:您有提出低质量问题的历史。请在您的问题上投入更多的思考、时间和精力。为了帮助您做到这一点,您每周可以提出的问题数量目前是有限的。欲了解更多信息。这个问题是低质量问题吗??
    • 不知道,我不是模组。也许你过去的问题有否决票/关闭投票。
    猜你喜欢
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    相关资源
    最近更新 更多