dsrnwngq411594 2014-05-27 03:41
浏览 44
已采纳

如何使用CodeIgniter更改multiupload中的图像名称?

I want to change image names when uploading more than one image. I have tried to use this config but it doesn't work $config['file_name'] = $this->getRandomString(); So, I need help with this

function addProductPhotoGallery() {
    if ($this->session->userdata('admin_login')) {
        $this->load->model('admin/admin_model');
        $gallery_photo = array();
        $gallery_path = realpath(APPPATH . '../imgs/product_pic/');
        $config1['upload_path'] = $gallery_path;
        $config1['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
        $config1['max_size'] = '2000';
        $this->load->library('upload', $config1);
        $this->upload->initialize($config1);
        $thum_path = realpath(APPPATH . '../imgs/product_pic/thumbs');
        $config = array(
            'image_library' => 'gd2',
            'source_image' => '',
            'maintain_ratio' => TRUE,
            'width' => 300,
            'height' => 200,
            'new_image' => $thum_path
        );
        $this->load->library('image_lib', $config);

        ///////////// for loop and code that upload  photo /////////////////////  
        $i = 1;
        foreach ($_FILES as $filey) {
            if (isset($_FILES['file' . $i])) {
                $config['file_name'] = $this->input->post('username').$this->getRandomString();
                // $_FILES['file' . $i]['name'] = $this->input->post('username').$this->getRandomString();
                if($this->upload->do_upload('file' . $i)){
                $phot_data = $this->upload->data();
                $gallery_photo[$i] = $phot_data['file_name'];
                $config['source_image'] = $phot_data['full_path'];
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
                $i++;
            }else{
                break;
                return false;

            }
            }
        }
        return serialize($gallery_photo);

    } else {
        redirect('civou/home');
    }
}

展开全部

  • 写回答

1条回答 默认 最新

  • doutuan6158 2014-05-27 17:02
    关注

    Try to putting $this->image_lib->clear() after $this->image_lib->resize() so that on the next loop the/a new $config['file_name'] is used.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部