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


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:

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);
            $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();
            $data['upload_data'] = $upload_data;            
            $this->load->view('upload_image', $data);


<title>Upload Form</title>
<h1>Upload Photo</h1>
&lt;?php  if(isset($error)){echo $error;}?&gt;

&lt;?php if(isset($upload_data)){ ?&gt;
        &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;
&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;



Where is my mistake??

Did you enable error display? What error did you get?

I dont get any error , just a blank page.

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

In ./index.php I have this:


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

upload_max_filesize = 32M

Also enable php error output in the ini file or using
ini_set('display_errors', 1);

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

In php.ini I set:

display_errors = On

I still get a blank page.

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

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