[eluser]zazvorniki[/eluser]
This is driving me a little nutty. I'm working on a user uploading a profile image, but if that image is too large I would like to resize it and then replace the original image. This way I'm not hosting huge images on my website.
Anyway, the first piece of code is working just fine. I'm uploading the original file to the right folder, but I'm having trouble with the resize and replace.
Code:
public function profilePic(){
if (empty($this->user)) {
redirect('/home/');
}else{
$config['upload_path'] = './uploads/';
$config['file_name'] = $this->user->pen_name.'.jpg';
$config['file_path'] = './uploads/'.$this->user->pen_name.'.jpg';
$config['max-size'] = 2000;
$config['create_thumb'] = TRUE;
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
var_dump($error);
}else{
$config2['image_library'] = 'gd2';
$config2['source_image'] = $config['file_path'];
$config2['new_image'] = './upload/'.$this->user->pen_name.'.jpg';
$config2['maintain_ratio'] = TRUE;
$config2['create_thumb'] = TRUE;
$config2['thumb_marker'] = '_thumb';
$config2['width'] = 200;
$config2['height'] = 300;
$config2['overwrite'] = TRUE;
$this->load->library('image_lib',$config2);
$this->load->library('upload', $config2);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}else{
$this->users_model->uploadPic($config2['new_image']);
redirect($_SERVER['HTTP_REFERER']);
}
}
}
}
Any help is much appreciated!
edit: sorry the closing brakets are off....I can't seem to get them formatted properly here.