I'm uploading profile pictures to my website and the first upload is working fine, but when I try and resize the image and reupload it to the same folder it breaks. From testing, I know it is going through the array and it is inserting the data into the database, but just not re-saving into the folder.
This is what I have going one.
$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['overwrite'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['remove_spaces'] = true;
$config['max_width'] = 2000;
$config['max_height'] = 3000;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()){
$error = array('error' => $this->upload->display_errors());
}else{
$resize['source_image'] = base_url().'/uploads/'.$config['file_name'];
$resize['new_image'] = './uploads/';
$resize['file_path'] = './uploads/'.$this->user->pen_name.'.jpg';
$resize['create_thumb'] = false;
$resize['maintain_ratio'] = true;
$resize['width'] = 200;
$resize['height'] = 300;
$resize['overwrite'] = TRUE;
$this->load->library('image_lib', $resize);
$this->image_lib->resize();
$this->load->library('upload', $resize);
$this->users_model->uploadPic($resize['file_path']);
redirect($_SERVER['HTTP_REFERER']);
}
Any help would be much appreciated!
Just had the same issue, and solved it as follows:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('logoUpload')) {
$this->data['error'] = array('error' => $this->upload->display_errors('<div class="alert alert-danger">', '</div>'));
//error
} else {
$upload_data = $this->upload->data();
//resize:
$config['image_library'] = 'gd2';
$config['source_image'] = $upload_data['full_path'];
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
//add to the DB
$this->settings_model->upload_logo($upload_data);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With