简体   繁体   中英

Codeigniter 3 upload not saving thumb to directory

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM