Codeigniter thumbnail image path can not be stored in MySql
$thumbnail_path = './uploads/'. $thumbnail;
So thumbnail_path
contains only "./uploads/" : that tells us that $thumbnail
is false (or null or empty string etc.), meaning that the return value of the call to resize is wrong - it seems you expect it to return the file name.
function resize($path, $file) { $config['image_library'] = 'gd2'; $config['source_image'] = $path; $config['create_thumb'] = TRUE; $config['maintian_ratio'] = TRUE; $config['width'] = 100; $config['height'] = 100; $config['new_image'] = './uploads/' . $file; $this->load->library('image_lib', $config); $this->image_lib->resize();}
resize
returns nothing! And you assign that nothing to $thumbnail_path
. That's your problem.
You seem to have simply copied the code from the CodeIgniter docs. From said docs (emphasis mine):
The above code tells the image_resize function to look for an image called mypic.jpg located in the source_image folder, then create a thumbnail that is 75 X 50 pixels using the GD2 image_library. Since the maintain_ratio option is enabled, the thumb will be as close to the target width and height as possible while preserving the original aspect ratio. The thumbnail will be called mypic_thumb.jpg
So there you have it! If your filename is $data['upload_data']['file_name']
, your thumbnail will be $data['upload_data']['file_name'] . "_thumb"
. Have a look at your file system, the files should be there for you to see.
So to fix your problem, this should do the trick:
$pathinfo = pathinfo($data['upload_data']['file_name']); $thumbnail_path = './uploads/'. $data['upload_data']['file_name'] . "_thumb" . $pathinfo['extension'];