Codeigniter 3上传不保存拇指到目录

时间:2015-06-19 16:08:39

标签: php codeigniter

我正在尝试将缩略图保存到目录中,但它无法正常工作。我能够保存原始图像并将信息保存到数据库,但由于某种原因,缩略图没有保存到我创建的thumb目录中。该目录具有读/写访问权限。我还会注意到我正在使用Dropzone.js。

这是我的部分代码:

 if ( ! $this->upload->do_upload('file'))
 {
     //upload failed, echo back negative response to dropzone.js

   }
   else 
   {
            //upload success, upload file(s)
            $image_data = $this->upload->data();

            $img_config['source_image']   = '/uploads/videos/'.$image_data['file_name'];
            $img_config['new_image']      = '/uploads/videos/thumbs/'.$image_data['file_name'];
            $img_config['create_thumb']   = TRUE;
            $img_config['maintain_ratio'] = TRUE;
            $img_config['width'] = 251;
            $img_config['height'] = 180;

            $this->load->library('image_lib', $img_config);

            $this->image_lib->resize();

            $file = array(
              'user_id'     =>  $this->my_auth->logged_in(),
              'img_name'    =>  $image_data['raw_name'],
              'thumb_name'  =>  $image_data['raw_name'].'_thumb',
              'ext'         =>  $image_data['file_ext'],
              'upload_date' =>  time()
            ); 

            $this->upload_model->add_image($file);              

            $data['img_success'] = '<div class="alert alert-success" id="imgSuccess">Your image <strong>' . $image_data['file_name'] . '</strong> was successfully uploaded!</div>';  

            $this->load->view('templates/frontend/front_header', $data);
            $this->load->view('templates/frontend/front_navbar');
            $this->load->view('frontend/upload_images', $data);
            $this->load->view('templates/frontend/front_footer', $data);                         
        }    

我能够成功保存原始图像,而不是缩略图。谁能在这里看到任何错误?

1 个答案:

答案 0 :(得分:0)

我将此添加到我的__construct

$this->original_path = realpath(APPPATH.'../uploads/images');
$this->thumbs_path = realpath(APPPATH.'../uploads/images/thumbs');

并更改了source_imagenew_image配置:

$img_config['source_image']   = $image_data['full_path'];
$img_config['new_image']      = $this->thumbs_path;

这似乎解决了这个问题。