[eluser]rich.a.coy[/eluser]
I'm trying to rename an image that has been uploaded and resized so that it has the format of userid_thumb.xxx where userid is the sessions user_id. The code below gets it renamed properly in the database but the actual image still is getting the original files name plus '_thumb'
Also, if someone could tell me where/how to unset the original image that would be great; I only want to store the generated thumbnail.
Code:
function doUpload() {
$config['upload_path'] = './user_photos/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '8000';
$config['max_width'] = '9920';
$config['max_height'] = '9280';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
redirect('/profile#photo');
}
else
{
$fInfo = $this->upload->data();
$this->_createThumbnail($fInfo['file_name']);
$data = array(
'photo_url' => $this->session->userdata('user_id') . '_thumb' . $fInfo['file_ext']
);
$this->profile_model->update_profile($data);
$data['uploadInfo'] = $fInfo;
$data['thumbnail_name'] = $this->session->userdata('user_id') . '_thumb' . $fInfo['file_ext'];
redirect('/profile#photo');
}
}
function _createThumbnail($fileName) {
$config['image_library'] = 'gd2';
$config['source_image'] = './user_photos/' . $fileName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 125;
$config['height'] = 125;
$this->load->library('image_lib', $config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
}
Thanks in advance for your help!
[edit]
I got the renaming of the file to work by adding the following to the config settings:
Code:
$config['file_name'] = $this->session->userdata('user_id');
$config['overwrite'] = TRUE;
Still not sure how to unset the fullsize image to remove it from the directory.