Welcome Guest, Not a member yet? Register   Sign In
best way to upload and rename an image
#5

[eluser]FuzzyJared[/eluser]
that does make sense. I have found an interesting piece that I did not notice happening. Basically as long as the overwrite is set to false the image will be saved with a number extended onto the end of it. What I didn't realize is that durring my insertion of data into the db was that if it was renamed then the final name was being inserted into the db.

As an example, if I upload my_image.jpg twice, I will have 2 physical images (my_image.jpg and my_image1.jpg). And within my insert, it is recognizing the actual name of the my_image1.jpg so I don't have to change the name.

Code:
$config['upload_path'] = realpath(BASEPATH.'../product_images/');
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size']    = '100';
                $config['max_width']  = '1024';
                $config['max_height']  = '768';
                $now = time();
                
                
                $this->load->library('upload', $config);
                $this->upload->initialize($config);
                if ( ! $this->upload->do_upload())
                {
                    if ($_POST) {
                        
                        $data['error'].= ''.$this->upload->display_errors();
                    }
                }    
                else
                {
                    
                    $data .= array('upload_data' => $this->upload->data());
                    $upload_data = $this->upload->data();
                    $image_path = $upload_data['full_path'];
                    $extension = $upload_data['file_ext'];
                    $uploaded_image_name = $upload_data['raw_name'];
                    
                    $some_new_image_path = realpath(BASEPATH.'product_images/');
                    
                    $config['image_library'] = 'GD2';
                    $config['source_image'] = $image_path;
                    $config['new_image'] = './system/product_images/m/'.$uploaded_image_name . $extension;
                    $config['maintain_ratio'] = TRUE;
                    $config['width'] = 640;
                    $config['height'] = 400;
                    
                    $this->load->library('image_lib'); // load the image library
                    $this->image_lib->initialize($config);
                    if ( ! $this->image_lib->resize())
                    {
                       // error
                    }
                    
                    
                    $config['new_image'] = './system/product_images/t/'.$uploaded_image_name . $extension;
                    $config['width'] = 125;
                    $config['height'] = 125;
                    
                    $this->image_lib->clear(); // clear the old config data
                    $this->image_lib->initialize($config);
                    if ( ! $this->image_lib->resize())
                    {
                       // error
                    }
                    $uploaded_image_name = $upload_data['raw_name'].$upload_data['file_ext'];    
                }


Messages In This Thread
best way to upload and rename an image - by El Forum - 10-23-2007, 01:54 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 02:34 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 02:36 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 02:40 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 02:41 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 02:48 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 02:53 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 02:55 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 03:02 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 03:04 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 03:16 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 03:29 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 04:13 PM
best way to upload and rename an image - by El Forum - 10-23-2007, 07:49 PM
best way to upload and rename an image - by El Forum - 10-24-2007, 10:49 AM
best way to upload and rename an image - by El Forum - 10-24-2007, 12:17 PM
best way to upload and rename an image - by El Forum - 10-24-2007, 02:31 PM
best way to upload and rename an image - by El Forum - 10-24-2007, 03:29 PM
best way to upload and rename an image - by El Forum - 10-24-2007, 03:44 PM
best way to upload and rename an image - by El Forum - 10-30-2007, 04:57 PM
best way to upload and rename an image - by El Forum - 03-22-2008, 02:18 AM
best way to upload and rename an image - by El Forum - 03-24-2008, 10:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB