Picture resize function when uploading in CodeIgniter not working - php

I made a function on the CodeIgniter framework so users can upload pictures of products to a product page. The thing is I want pictures to be resized to the width and height I want it to be. Since I added the image lib resize function in my upload function nothing is working anymore.
This is my upload function:
public function upload() {
$this->load->library('upload');
if ( ! $this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('product_form', $error);
} else {
$file_data = $this->upload->data();
$this->load->library('image_lib');
foreach ($results as $row) {
$config['image_library'] = 'gd2';
$config['source_image'] = './upload/' . $file_data["file_name"];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
$this->db->insert('products', array(
'product_foto' => $file_data['file_name'],
'product_naam' => $this->input->post('product_naam'),
'product_beschrijving' => $this->input->post('product_beschrijving'),
'product_categorie' => $this->input->post('product_categorie'),
'ophaal_plaats' => $this->input->post('ophaal_plaats'),
'date_created' => date('Y-m-d'),
'date_updated' => date('Y-m-d')
));
$data['img'] = base_url() . '/upload/' . $file_data['file_name'];
header('location:https://kadokado-ferran10.c9users.io/Product/');
}
What am I doing wrong?

It works for me :
if(!empty($_FILES['image_field']['name']))
{
$config['upload_path'] = './image_folder';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '262144';
$config['overwrite'] = FALSE;
$this->load->library('upload',$config);
if(!$this->upload->do_upload('image_field'))
{
echo "Not Upload";
echo $this->upload->display_errors();
// $this->session->set_flashdata('error','<div class="alert alert-warning">Something went wrong...try again...</div>');
//redirect('Controller/function_name');
}
else
{
$image_data = $this->upload->data();
$config1['image_library'] = 'gd2';
$config1['source_image'] = './image_folder/'.$image_data['file_name'];
$config1['maintain_ratio'] = TRUE;
$config1['quality'] = '50%';
$config1['width'] = 50;
$config1['height'] = 50;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
echo $image_data['file_name'];
exit;
// save to database
}
}

Related

upload 2 or more image with different field name and different input in codeigniter

i want to upload several image with different input and different field name for each image. i actually try to separate it in two different method like this
public function tambahketua(){
if(isset($_POST["reg"]))
{
$config['upload_path'] = './asset/img/foto/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|xml|docx|GIF|JPG|PNG|JPEG|PDF|DOC|XML|DOCX|xls|xlsx';
$config['max_size'] = 200048;
$config['file_name'] = $this->input->post("namaketua");
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('attachment'))//ini name di input choose file
{
}
else
{
$datas = $this->upload->data();
$edit['image_library'] = 'gd2';
$edit['source_image'] = './asset/img/foto/'.$datas['file_name'];
$edit['create_thumb'] = TRUE;
$edit['maintain_ratio'] = TRUE;
$edit['height'] = 600;
$this->load->library('image_lib', $edit);
$this->image_lib->resize();
$edit_file = explode('.', $datas['file_name']);
$data['foto'] = $edit_file[0].'_thumb.'.$edit_file[1];
unlink($config['upload_path'].$datas['file_name']);
}
$a = $this->miniatur_model->insertPeserta($data);
if($a){
$this->tambahanggota1();
}
else{
echo "failed";
}
}
$this->load->view('pendaftaran');
}
public function tambahanggota1(){
if(isset($_POST["reg"]))
{
$config['upload_path'] = './asset/img/foto/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|xml|docx|GIF|JPG|PNG|JPEG|PDF|DOC|XML|DOCX|xls|xlsx';
$config['max_size'] = 200048;
$config['file_name'] = $this->input->post("namaanggota1");
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('fotoktmanggota1'))//ini name di input choose file
{
}
else
{
$datas = $this->upload->data();
$edit['image_library'] = 'gd2';
$edit['source_image'] = './asset/img/foto/'.$datas['file_name'];
$edit['create_thumb'] = TRUE;
$edit['maintain_ratio'] = TRUE;
$edit['height'] = 600;
$this->load->library('image_lib', $edit);
$this->image_lib->resize();
$edit_file = explode('.', $datas['file_name']);
$data['foto'] = $edit_file[0].'_thumb.'.$edit_file[1];
unlink($config['upload_path'].$datas['file_name']);
}
$a = $this->miniatur_model->insertPeserta($data);
if($a){
echo "success";
}
else{
echo "failed";
}
}
$this->load->view('pendaftaran');
}
and so far i could only write both of the image name into my database, but only the first one uploaded into my folder.
and this is my view
<input type="file" id="attachment" name="attachment">
<input type="file" id="fotoktmanggota1" name="fotoktmanggota1">
and for some reason i cant change the name of my files into array like name="attachment[]"
I have minimized your extra code. Try this and do your own magic if I missed something.
function tambahketua() {
if (isset($_POST["reg"])) {
$config['upload_path'] = './asset/img/foto/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|xml|docx|GIF|JPG|PNG|JPEG|PDF|DOC|XML|DOCX|xls|xlsx';
$config['max_size'] = 200048;
$this->upload->initialize($config);
if (!$this->upload->do_upload('attachment')) {
$error = array('error' => $this->upload->display_errors());
// var_dump($error);
} else {
$fileData = $this->upload->data();
$data['foto'] = $fileData['file_name'];
$this->doResize($fileData['file_name']);
}
$insertedFirstImage = $this->miniatur_model->insertPeserta($data);
if ($insertedFirstImage) {
// Upload Second Image on Success
if (!$this->upload->do_upload('fotoktmanggota1')) {
$error = array('error' => $this->upload->display_errors());
} else {
$fileData = $this->upload->data();
$data['foto'] = $fileData['file_name'];
$this->doResize($fileData['file_name']);
}
$insertedSecondImage = $this->miniatur_model->insertPeserta($data);
/*---------------------------------------*/
} else{
echo "Image insertion Failed in database";
}
}
$this->load->view('pendaftaran');
}
function doResize($filename) {
$sourcePath = './asset/img/foto/' . $filename;
$targetPath = './asset/img/foto/thumb/thumb_' . $filename;
$config_manip = array(
'image_library' => 'gd2',
'source_image' => $sourcePath,
'new_image' => $targetPath,
'maintain_ratio' => true,
'width' => 150,
'height' => 150
);
$this->image_lib->initialize($config_manip);
$this->load->library('image_lib', $config_manip);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
exit;
}
// clear //
// $this->image_lib->clear();
}

Codeigniter thumbnail array not working

Im doing multiple file uploading, which is working fine.
im getting both images but the other image which is thumnail not getting their given path and also not changing in to thumb size.
I have just issues with thumbnail in "thumbnail creation start" area i hope.
check my array and let me know my mistake.
controller codes
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $image['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 150;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
$this->upload->do_upload();
$data = $this->upload->data();
$name_array1[] = $data['file_name']; // file names for thumb
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function
Replace
$config1['source_image'] = $image['full_path'];
To
$config1['source_image'] = $data['full_path'];
Also remove the following commented lines
$this->image_lib->resize();
//$this->upload->do_upload();
//$data = $this->upload->data();
After you do config for your image i.e., setting your image attributes then you should clear and initizliae the image_lib to get effect.
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
Note :
Make sure that you need it for $config or $config1
Make sure that you have the source_image path right
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $data['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 500;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->clear();
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$name_array1[] = $data['file_name']; // get file names for thumb file
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function

How to change image name in multiupload with CodeIgniter?

I want to change image names when uploading more than one image. I have tried to use this config but it doesn't work $config['file_name'] = $this->getRandomString(); So, I need help with this
function addProductPhotoGallery() {
if ($this->session->userdata('admin_login')) {
$this->load->model('admin/admin_model');
$gallery_photo = array();
$gallery_path = realpath(APPPATH . '../imgs/product_pic/');
$config1['upload_path'] = $gallery_path;
$config1['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config1['max_size'] = '2000';
$this->load->library('upload', $config1);
$this->upload->initialize($config1);
$thum_path = realpath(APPPATH . '../imgs/product_pic/thumbs');
$config = array(
'image_library' => 'gd2',
'source_image' => '',
'maintain_ratio' => TRUE,
'width' => 300,
'height' => 200,
'new_image' => $thum_path
);
$this->load->library('image_lib', $config);
///////////// for loop and code that upload photo /////////////////////
$i = 1;
foreach ($_FILES as $filey) {
if (isset($_FILES['file' . $i])) {
$config['file_name'] = $this->input->post('username').$this->getRandomString();
// $_FILES['file' . $i]['name'] = $this->input->post('username').$this->getRandomString();
if($this->upload->do_upload('file' . $i)){
$phot_data = $this->upload->data();
$gallery_photo[$i] = $phot_data['file_name'];
$config['source_image'] = $phot_data['full_path'];
$this->image_lib->initialize($config);
$this->image_lib->resize();
$i++;
}else{
break;
return false;
}
}
}
return serialize($gallery_photo);
} else {
redirect('civou/home');
}
}
Try to putting $this->image_lib->clear()
after $this->image_lib->resize() so that on the next loop the/a new $config['file_name'] is used.

How to resize and create additional thumbnail in codeignite?

I am having trouble resizing photos that I am successfully uploading in my my upload module.
I am able to upload photos to the appropriate folder, however my resizing is not working and I also want to simultaneously create a thumbnail duplicate in the same folder.
public function upload()
{
$this->load->library('session');
$this->load->helper('url');
$session_id = $this->session->userdata('id');
$this->load->model('account_model');
$user = $this->account_model->user();
$data['user'] = $user;
echo $user['id'];
$user_folder = './uploads/' . $this->session->userdata('id');
if(!is_dir($user_folder)){
mkdir($user_folder, 0777);
}
$config['image_library'] = 'gd2';
$config['source_image'] = $user_folder;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 50;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$config['upload_path'] = $user_folder;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '165';
$config['max_width'] = '165';
$config['max_height'] = '165';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$data['main_content'] = '/account/upload';
$this->load->view('includes/templates/main_page_template', $data);
}
else
{
$data = array('upload_data' => $this->upload->data());
$data['main_content'] = '/account/success';
$this->load->view('includes/templates/main_page_template', $data);
}
}
Try this:
public function upload()
{
$this->load->library('session');
$this->load->helper('url');
$session_id = $this->session->userdata('id');
$this->load->model('account_model');
$user = $this->account_model->user();
$data['user'] = $user;
echo $user['id'];
$user_folder = './uploads/' . $this->session->userdata('id');
if(!is_dir($user_folder)){
mkdir($user_folder, 0777);
}
$this->load->library('image_lib'); #load the image manipulation library without initiatlising it here.
$configThumb['image_library'] = 'gd2';
//$configThumb['source_image'] = $user_folder;
$configThumb['create_thumb'] = TRUE;
$configThumb['maintain_ratio'] = TRUE;
$configThumb['width'] = 50;
$configThumb['height'] = 50;
//$this->image_lib->resize();
$config['upload_path'] = $user_folder;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '165';
$config['max_width'] = '165';
$config['max_height'] = '165';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$data['main_content'] = '/account/upload';
$this->load->view('includes/templates/main_page_template', $data);
}
else
{
$configThumb['source_image'] = $uploadedDetails['full_path'];
$this->image_lib->initialize($configThumb); #initialize the library here
$this->image_lib->resize(); #resize is done here
$data = array('upload_data' => $this->upload->data());
$data['main_content'] = '/account/success';
$this->load->view('includes/templates/main_page_template', $data);
}
}
Full path refers to the source image that is uploaded to your server. See the else condition you will get the idea. Now, the change is that we are loading the library and initializing it after uploading the image and hence we are getting the full path from $this->upload->data().
EDIT : MY WORKING FUNCTION TO CROP AN IMAGE IN TWO DIFFERENT SIZES
function udpate_profile($userId = 0){
$data = array();
//echo "<pre>";print_r($_POST);echo "</pre>";
/* Upload Image */
if($_FILES['image']['name'] != ""){
//echo "<pre>";print_r($_FILES);echo "</pre>";
//echo "enter";die;
/* Check if previous file exists */
$chkRs = $this->db->select('image')->where('id', $this->session->userdata['logged_user']['id'])->get('admins');
//echo $this->db->last_query();die;
if($chkRs->num_rows() > 0){
$chkD = $chkRs->row_array();
if($chkD['image'] != ""){
### delete the previous image ###
$pathActual = './profile_images/';
$pathMedium = './profile_images/medium/';
$pathThumb = './profile_images/thumbs/';
if(file_exists($pathActual.$chkD['image'])){ #delete the actual image
unlink($pathActual.$chkD['image']);
}
if(file_exists($pathMedium.$chkD['image'])){ #delete the medium image
unlink($pathMedium.$chkD['image']);
}
if(file_exists($pathThumb.$chkD['image'])){ #delete the thumb image
unlink($pathThumb.$chkD['image']);
}
### delete the previous image ###
}
}
/* Check if previous file exists */
//print_r($_FILES['image']);die;
$this->load->library('image_lib');
$configUpload['upload_path'] = './profile_images/';
$configUpload['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$configUpload['max_size'] = '0';
$configUpload['max_width'] = '0';
$configUpload['max_height'] = '0';
$configUpload['encrypt_name'] = true;
$this->load->library('upload', $configUpload);
/* size 64*72 for comments */
$configThumb = array();
$configThumb['image_library'] = 'gd2';
$configThumb['create_thumb'] = TRUE;
$configThumb['new_image'] = './profile_images/thumbs/';
$configThumb['maintain_ratio'] = TRUE;
$configThumb['width'] = 64;
$configThumb['height'] = 72;
$configThumb['thumb_marker'] = "";
//$this->load->library('image_lib');
/* size 64*72 for comments */
/* size 167*167 for profile page */
$configThumbMedium = array();
$configThumbMedium['image_library'] = 'gd2';
$configThumbMedium['create_thumb'] = TRUE;
$configThumbMedium['new_image'] = './profile_images/medium/';
$configThumbMedium['maintain_ratio'] = TRUE;
$configThumbMedium['width'] = 167;
$configThumbMedium['height'] = 167;
$configThumbMedium['thumb_marker'] = "";
/* size 167*167 for profile page */
if(!$this->upload->do_upload('image')){
return 0;
}
$uploadedDetails = $this->upload->data();
if($uploadedDetails['is_image'] == 1){
$configThumb['source_image'] = $uploadedDetails['full_path'];
$configThumbMedium['source_image'] = $uploadedDetails['full_path'];
$raw_name = $uploadedDetails['raw_name'];
$file_ext = $uploadedDetails['file_ext'];
$imgname = $raw_name.$file_ext;
$this->image_lib->initialize($configThumb);
$this->image_lib->resize();
$this->image_lib->initialize($configThumbMedium);
$this->image_lib->resize();
}
}
//die();
/* Upload Image */
$data = $this->input->post(null);
//echo "<pre>";print_r($data);echo "</pre>";die;
if(isset($imgname) && $imgname != ""){
$data['image'] = $imgname;
}
$this->db->where('id',$this->session->userdata['logged_user']['id'])->update('admins', $data);
return 1;
}
it's likely you need to pass source_image the full path of the image on the server. so if you're trying to use /uploads, then it's likely you'll need to set it as /var/www/html/uploads or whatever the full path is to that folder since the image processing is relative to the server, not the site url

Multiple Image Resizes at once in Codeigniter , won't work

I am trying to upload images and re-size them in different dimensions within the same function. but what happens is that only one re-size works and the others don't . My code is:
function do_upload()
{
$this_user = $this->auth->info;if(!is_dir('./uploads/'.$this_user->username)){
mkdir('./uploads/'.$this_user->username);
mkdir('./uploads/'.$this_user->username.'/photos');
mkdir('./uploads/'.$this_user->username.'/photos/master');
mkdir('./uploads/'.$this_user->username.'/photos/small');
mkdir('./uploads/'.$this_user->username.'/photos/medium');
mkdir('./uploads/'.$this_user->username.'/photos/large');
mkdir('./uploads/'.$this_user->username.'/photos/xlarge');
}
$config['upload_path'] = './uploads/'.$this_user->username.'/photos/master/';
$config['allowed_types'] = 'gif|jpg';
$title = $this->input->post('title');
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
echo '<div id="status">error</div>';
echo '<div id="message">'. $this->upload->display_errors() .'</div>';
}
else
{
$data = array('upload_data' => $this->upload->data());
//resizing begins
$image_width = $data['upload_data']['image_width'];
$image_height = $data['upload_data']['image_height'];
$full_path = $data['upload_data']['full_path'];
//checking for width
if($image_width>5000){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 5000;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/xlarge';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
if($image_width>=4500){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 4500;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/large';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
if($image_width>=2000){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 2000;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/medium';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
if($image_width>=800){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 800;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/small';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
//resizing ends
echo '<div id="status">success</div>';
//then output your message (optional)
echo '<div id="message">'. $data['upload_data']['file_name'].$this->input->post('type').' Successfully uploaded.</div>';
//pass the data to js
echo '<div id="upload_data">'. json_encode($data) . '</div>';
}
}
What Am I doing wrong here?
You will need to make sure that you call $this->image_lib->clear(); as it resets the initialization of the image manipulation class. See: http://codeigniter.com/user_guide/libraries/image_lib.html
this actually worked for me. What i was doing was loading the library multiple times. i should have loaded the library once and initialize the configurations for each re-sizes. here is the code that worked for me.
function do_upload()
{
$this_user = $this->auth->info;
if(!is_dir('./uploads/'.$this_user->username)){
mkdir('./uploads/'.$this_user->username);
mkdir('./uploads/'.$this_user->username.'/photos');
mkdir('./uploads/'.$this_user->username.'/photos/master');
mkdir('./uploads/'.$this_user->username.'/photos/small');
mkdir('./uploads/'.$this_user->username.'/photos/medium');
mkdir('./uploads/'.$this_user->username.'/photos/large');
mkdir('./uploads/'.$this_user->username.'/photos/xlarge');
}
$config['upload_path'] = './uploads/'.$this_user->username.'/photos/master/';
$config['allowed_types'] = 'gif|jpg';
$title = $this->input->post('title');
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
echo '<div id="status">error</div>';
echo '<div id="message">'. $this->upload->display_errors() .'</div>';
}
else
{
$data = array('upload_data' => $this->upload->data());
//resizing begins
$image_width = $data['upload_data']['image_width'];
$image_height = $data['upload_data']['image_height'];
$full_path = $data['upload_data']['full_path'];
//checking for width
$this->load->library('image_lib');
if($image_width>5000){
$config['source_image'] = $full_path;
$config['maintain_ratio'] = TRUE;
$config['width'] = 5000;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/xlarge';
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$aa = 'xlarge ';
}
if($image_width>=4500){
$config['source_image'] = $full_path;
$config['maintain_ratio'] = TRUE;
$config['width'] = 4500;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/large';
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$aa .= 'large';
}
if($image_width>=2000){
$config['source_image'] = $full_path;
$config['maintain_ratio'] = TRUE;
$config['width'] = 2000;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/medium';
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$aa .= 'medium';
}
if($image_width>=800){
$config['source_image'] = $full_path;
$config['maintain_ratio'] = TRUE;
$config['width'] = 800;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/small';
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$aa .= 'small';
}
//resizing ends
echo '<div id="status">success</div>';
//then output your message (optional)
echo '<div id="message">'. $data['upload_data']['file_name'].$aa.' Successfully uploaded.</div>';
//pass the data to js
echo '<div id="upload_data">'. json_encode($data) . '</div>';
}
}

Categories