dongxinyue2817 2015-06-19 16:08
浏览 32
已采纳

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

I am trying to save the thumbnail image to the directory, but it is not working. I am able to save the original image and save info to database, but for some reason the thumbnail is not saving to the thumbs directory I create. The directory has read/write access. I will also note I am using Dropzone.js.

Here is my partial code:

 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);                         
        }    

I am able to successfully save the original image, just not the thumbnail. Can anyone see anything wrong here?

  • 写回答

1条回答 默认 最新

  • doulai8405 2015-06-19 16:31
    关注

    I added this to my __construct:

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

    and changed the source_image and new_image configs:

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

    This seems to have fixed it.

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

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题