Welcome Guest, Not a member yet? Register   Sign In
What is wrong in this resize() function?
#1

[eluser]chefnelone[/eluser]
Hello

I have this code to upload a image and resize it if the width or height of the uploaded image is bigger than 500px.

I works fine with a image of: 800px X 600px (width x height) ...but it doesn't work with a image of: 1200px X 900px

This is the real code:


controllers/index.php
Code:
class Index extends MY_Controller{

    function upload_image(){
    
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '5000';
        $config['max_width']  = '5000';
        $config['max_height']  = '5000';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload()) {
        
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_image', $error);
        
        }else{
            $upload_data = $this->upload->data();
        
            if($upload_data['image_width'] > 500 || $upload_data['image_height'] > 500  ){    
    
                $config['image_library'] = 'gd2';
                $config['source_image'] = './uploads/'.$upload_data['file_name'];
                $config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 500;
                $config['height'] = 500;
                
                $this->load->library('image_lib', $config);
                if ( ! $this->image_lib->resize()){
                    $error =  $this->image_lib->display_errors();
                    print_r($error);
                }
            }            
            $data['upload_data'] = $upload_data;            
            $this->load->view('upload_image', $data);
        }
    }

}

views/upload_image.php
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h1>Upload Photo</h1>
&lt;?php  if(isset($error)){echo $error;}?&gt;

&lt;?php if(isset($upload_data)){ ?&gt;
    <ul>
        &lt;?php foreach($upload_data as $item => $value):?&gt;
        <li>&lt;?php echo $item;?&gt;: &lt;?php echo $value;?&gt;</li>
        &lt;?php endforeach; ?&gt;
    </ul>
&lt;?php } ?&gt;

&lt;?php echo form_open_multipart('index/upload_image');?&gt;

&lt;input type="file" name="userfile" size="20" /&gt;

<br /><br />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

Where is my mistake??
#2

[eluser]Clooner[/eluser]
Did you enable error display? What error did you get?
#3

[eluser]chefnelone[/eluser]
I dont get any error , just a blank page.

In config/config.php I have this:
Code:
$config['log_threshold'] = 1; //1 = Error Messages (including PHP errors)
#4

[eluser]chefnelone[/eluser]
In ./index.php I have this:

Code:
error_reporting(E_ALL);

and in php.ini the max filesize is set to 32mb

Code:
upload_max_filesize = 32M
#5

[eluser]Clooner[/eluser]
Also enable php error output in the ini file or using
Code:
ini_set('display_errors', 1);
#6

[eluser]chefnelone[/eluser]
[quote author="Jeroen Schaftenaar" date="1282140089"]Also enable php error output in the ini file or using
Code:
ini_set('display_errors', 1);
[/quote]
thanks jeroen

In php.ini I set:

Code:
display_errors = On


I still get a blank page.

Where (which file) do I set: ini_set('display_errors', 1) ?
#7

[eluser]chefnelone[/eluser]
Near to find the problem

There's no problem with the resize function.

It is a problem of my local server, because I uploaded the site to my hosting and it works fine.

I use MAMP for running my site in my localhost.

The problem should be in php.ini ??
I have:
upload_max_filesize = 32M;

What else could be??




Theme © iAndrew 2016 - Forum software by © MyBB