Welcome Guest, Not a member yet? Register   Sign In
Function stopped working!
#1

[eluser]wakey[/eluser]
Hi everyone,

Been getting to grips with codeigniter the last few weeks and made some good progress. Tonight I was working on a function to upload an image, resize the image and make a thumbnail of the image. It was working perfectly and then for some reason it stopped working and I can't work out what I've done wrong.

If anyone could have a look over and point out the error it'd be much appreciated as I can't see it.

Code:
function upload()
        {
            $config['upload_path'] = './gallery/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '0';
            $config['max_width']  = '0';
            $config['max_height']  = '0';
            $config['encrypt_name'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            
            $this->load->library('upload', $config);
            
        
            if ( ! $this->upload->do_upload())
            {
                $error = array('error' => $this->upload->display_errors());
                
                redirect('add-location');
            }
            
            else
            {        
            
                   $configThumb = array();  
                   $configThumb['image_library'] = 'gd2';
                   $configThumb['new_image'] = './gallery/thumbs/';
                   $configThumb['source_image'] = '';  
                   $configThumb['create_thumb'] = TRUE;  
                   $configThumb['maintain_ratio'] = TRUE;
                   $configThumb['quality'] = '70%';
                   $configThumb['width'] = 100;  
                   $configThumb['height'] = 100;
                  
                  
                  
                $data = array('upload_data' => $this->upload->data());
                
                  $up_data = $this->upload->data();
                  $config2 = array();  
                  $config2['image_library'] = 'gd2';
                  $config2['source_image'] = '';
                  $config2['quality'] = '100%';
                  $config2['maintain_ratio'] = TRUE;
                if( ( $up_data['image_width'] > 500 ) || ( $up_data['image_height'] > 333 ) ) {
                    if( $up_data['image_width'] > $up_data['image_height'] ) {
                        $ratio = ($up_data['image_width'] / $up_data['image_height']);
                        $config2['height'] = 333;
                        $config2['width'] = 500 * $ratio;
                    } else {
                        $ratio = ($up_data['image_height'] / $up_data['image_width']);
                        $config2['width'] = 500;
                        $config2['height'] = 333 * $ratio;
                    }
                }
        
                
                $img_data = $this->upload->data();                
                
                   $file_name = $img_data['file_name'];
                
                $thumb_ext = $img_data['file_ext'];
                $thumb_path = $img_data['raw_name'];
                
                $config2['source_image'] = $img_data['full_path'];
                $configThumb['source_image'] = $img_data['full_path'];
                
                $this->load->library('image_lib');
                
                $this->image_lib->initialize($config2);
                 $this->image_lib->resize();
              
                  $this->image_lib->initialize($configThumb);
                $this->image_lib->resize();
                
                $this->load->model('upload_model');
            
                $query = $this->upload_model->upload($file_name,$thumb_path,$thumb_ext);                
                
                if ($query)
                {
                
                    $data['main_content'] = 'add-success';
                    $data['tab'] = 'view';
                    $data['page'] = 'Location Successfully Added';
                    //$data['test'] = $file_name;
                    
                    $this->load->view('template', $data);
                }
            }
        }

I am receiving no error messages, the page is white as if it can't load.

It is definitely uploading the first image to the gallery image but then it is getting stuck in the else statement.

I appreciate any help. Thanks.
#2

[eluser]cahva[/eluser]
You've probably hit the memory limit that your script can use. This can happen on large pictures when resizing as its very memory consuming. Does it work on smaller pictures? Check your error logs to see the actual problem. If its a memory problem, you must pump up memory_limit. If you're on shared server, ask your host to do that.
#3

[eluser]JoostV[/eluser]
If you do have memory problems, change to lib imagemagick instead of GD2. It consumes MUCH less memory.
#4

[eluser]Aniket[/eluser]
As per your code ..you haven't specified the size for the image files to be uploaded...pls provide the size...and try doing the upload process again....also enable logging from the config.php file so that you can debug using error messages....also enable error reporting...if possible use echo statements to debug and find the exact piece of code causing the issue Smile.
Hope this helps
#5

[eluser]wakey[/eluser]
Hey,

Thanks for the replies. I'm just working on localhost at the moment, got back tonight after work, tried the function and it's working again.

Could this be a problem with the memory as previously mentioned? And could this cause problems when I get the website online (shared hosting)?




Theme © iAndrew 2016 - Forum software by © MyBB