Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems with thumb creation
    text
    copied!<p>I am currently using codeigniter 2.0 for a project and I have a little problem with thumb creation. I intend to allow users to upload picture and have the picture renamed to their last name then have anoda function from within the upload function create a thumbnail then send it to another directory inside the image directory (I named it avatar). The code does this perfectly, but now I intend to encrypt the last name before changing the uploaded pic name. That is where the problem sets in. The upload is carried out the name is changed but a thumbnail is not created ... please can any one tell me what the problem is here is the code sample</p> <pre><code>function set_avatar() { /*check if user is even logged in */ if($this-&gt;session-&gt;userdata('user_id')) { $last_name=$this-&gt;session-&gt;userdata('last_name');//this value is encrypted /*parse the useful user values to the data array for use on this page */ $data['user_id']= $user_id; $data['email']= $email; $data['last_name']= $last_name; $data['first_name']= $first_name; /*assign an empty value to the error key of the data array to avoid error on the view page*/ $data['error'] = ""; /*the directory for uploading the file the number represents a mixture of birth date and month af means all files u1 upload 1 avts avatar ..jst a path to make the path undetectable*/ $dir = "./path/avatar"; /*preparing the config settings for upload */ $config['file_name'] = $last_name; // the new file name the image should have $config['upload_path'] = $dir; // the directory the image should go to,already specified $config['allowed_types'] = 'gif|jpg|png'; // the file types that are allowed $config['max_size'] = '10000'; //the maximum image size $config['max_width'] = '300'; //the maximum image width $config['max_height'] = '230'; // the maximum image height $this-&gt;load-&gt;library('upload', $config); // retrieving the upload library with the specified settings /*using the do upload settings upload the file if it fails stop upload and show errors*/ if ( ! $this-&gt;upload-&gt;do_upload()) { $data['error'] = $this-&gt;upload-&gt;display_errors(); $this-&gt;load-&gt;view("user/set_avatar",$data); } /*else retrieve the upload data from the file uploaded*/ else { /*pass all the upload data to the $img_data array*/ $img_data = $this-&gt;upload-&gt;data(); /*the file(image) extension type png or gif or jpg*/ $img_ext = $img_data['file_ext']; /*thumb name without extension*/ $thumb = $last_name; /*thumb name with extension*/ $thumb_name = $thumb.$img_ext; /*create thumbnail using the thumb nail function*/ $this-&gt;create_thumb($thumb_name); /*record avatar details in the db*/ $avatar_array = array( "user_id" =&gt; $user_id, "avatar" =&gt; $thumb, "extension" =&gt; $img_ext ); $this-&gt;craft_set_user_details-&gt;set_avatar($avatar_array); /*start creat session for img_name and ext*/ $image_session = array( "img_name"=&gt;$thumb, "img_ext"=&gt;$img_ext ); $this-&gt;session-&gt;set_userdata($image_session); /*redirect to home page*/ redirect('home','location'); }//end if else $this-&gt;upload-&gt;do_upload }//end check if user is logged in ($this-&gt;session-&gt;userdata('user_id')) else { redirect("index"); }//end if eles user is logged in ($this-&gt;session-&gt;userdata('user_id')) }//end function set avatar /* this is the create_thumb() function */ ///start the create thumb function this is used in the set avatar function to create the avatar thumb function create_thumb($thumb_name) { /*check if user is logged in*/ if($this-&gt;session-&gt;userdata('user_id')) { //set the path to were the image is $dir = "./path/avatar"; //set the path to were the thumb should be sent $new = "./path/avatar/thumbs"; //set the configuration to be used for image resizing $config['image_library'] = 'gd2'; $config['source_image'] = $dir; $config['new_image'] = $new; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 35; $config['height'] = 50; //load the image library for image reszing $this-&gt;load-&gt;library('image_lib', $config); //resize image $this-&gt;image_lib-&gt;resize(); }//end if eles user is logged in ($this-&gt;session-&gt;userdata('user_id')) //else redirect to the home page else { redirect('index','location'); } }//end function to create </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload