I'm receiving the following error when I try to create a thumbnail from an image that was uploaded:
However, when I echo the source image it was uploaded and the file exists but it's not finding the image.
The function from the controller
public function addgallery(){
$year = date('Y');
$date = str_replace( ':', '', $year);
// Fetch a user or set a new one
$this->data['page_title'] = 'Add New Gallery';
$this->data['gallery'] = $this->gallery_m->get_new();
// Set up the form
$rules = $this->gallery_m->rules_admin;
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == TRUE || !empty($_FILES['thumbnail']['name'])) {
if ( !$this->upload->do_upload('thumbnail')){
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}else{
//file is uploaded successfully
//now get the file uploaded data
$imagedata = $this->upload->data();
//get the uploaded file name
$image['pic_file'] = base_url().'assets/uploads/thumbnail/'.$date.'/'.$imagedata['file_name'].'-150x150';
$thumbnail['pic_file'] = $this->gallery_m->resizeimage($imagedata['file_name']);
$data = array('name' => $this->input->post('name'), 'description' => $this->input->post('description'), 'thumbnail' => $image['pic_file'], 'datesubmitted' => date('Y-m-d'));
//store pic data to the db
$this->gallery_m->qsave($data);
$this->session->set_flashdata( 'message', 'Gallery Added Successfully' );
}
}
// Load the view
$this->data['subview'] = 'admin/gallery/addgallery';
$this->load->view( 'admin/body', $this->data );
}
The function from the model
public function resizeimage($filename){
$year = date('Y');
$date = str_replace( ':', '', $year);
$image_sizes = array(
'thumb' => array(150, 100),
'medium' => array(300, 300),
'large' => array(800, 600)
);
$source_path = base_url().'assets/uploads/original/'.$date.'/'.$filename;
$target_path = base_url().'assets/uploads/thumbnail/'.$date.'/';
foreach ($image_sizes as $resize) {
$config['image_library'] = 'GD2';
$config['source_image'] = $source_path;
$config['new_image'] = $target_path;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['quality'] = '100';
$config['thumb_marker'] = $resize[0].'x'.$resize[1];
$config['width'] = $resize[0];
$config['height'] = $resize[1];
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->image_lib->resize();
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
echo 'Source: '.$source_path.'<br /><br />';
echo 'Target: '.$target_path.'<br /><br />';
}
}
$this->image_lib->clear();
}
For the most part, the function does as it should. The image is uploaded and the image and thumbnail path is saved to the database. But the thumbnail not generating.
I've tried a few examples I found on here but none of them seem to solve the problem.