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

时间:2014-05-27 11:41:47

标签: php codeigniter

我想在上传多张图片时更改图片名称。我试图使用此配置,但它不起作用$config['file_name'] = $this->getRandomString();所以,我需要帮助这个

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 个答案:

答案 0 :(得分:0)

尝试放$this->image_lib->clear()$this->image_lib->resize()之后,在下一个循环中使用/ {$config['file_name']