[eluser]jvk22[/eluser]
I am trying to create a thumbnail and resize an image when uploaded, but when I call both functions, the one called first is the only one that works.
Code:
public function do_upload()
{
$target_path = "assets/uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
$data = array(
'title'=>$this->ci->input->post('title'),
'email'=>$this->ci->input->post('email'),
'image_location'=>$_FILES['uploadedfile']['name'],
'about_me'=>$this->ci->input->post('about_me'),
'date_uploaded'=>date("Y-m-d h:i:s")
);
$insert_id = $this->ci->upload_model->add_photo($data);
mkdir('assets/uploads/'.$insert_id);
copy('assets/uploads/'.basename( $_FILES['uploadedfile']['name']), 'assets/uploads/'.$insert_id.'/'.basename( $_FILES['uploadedfile']['name']));
unlink('assets/uploads/'.basename( $_FILES['uploadedfile']['name']));
//$this->create_thumbnail('assets/uploads/'.$insert_id.'/'.basename( $_FILES['uploadedfile']['name']));
$this->resize_image('assets/uploads/'.$insert_id.'/'.basename( $_FILES['uploadedfile']['name']));
$this->create_thumbnail('assets/uploads/'.$insert_id.'/'.basename( $_FILES['uploadedfile']['name']));
return array('success'=>'The file '. basename( $_FILES['uploadedfile']['name']). ' has been uploaded');
}
else
{
return array('error'=>'There was an error uploading the file, please try again!');
}
}
public function resize_image($path)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $path;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = false;
$config['width'] = 250;
// $config['height'] = 50;
$this->ci->image_lib->initialize($config);
$this->ci->image_lib->resize();
}
public function create_thumbnail($path)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $path;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 125;
// $config['height'] = 50;
$this->ci->image_lib->initialize($config);
$this->ci->image_lib->resize();
}