dsrnwngq411594 2014-05-27 11: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-28 01: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.

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

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大