0

I am using the following function to upload image file and resize.

    public function upload()
    {
        include_once 'wideimage/WideImage.php';

        $ext = $this->detect_type();

        $file_name = 'uploads/' . time() . $ext;

        if( move_uploaded_file($_FILES['file']['tmp_name'], $file_name ) )
        {
            $data[] = array(
                'status' => true,
            );
        }

        else
        {
            $data[] = array(
                'status' => false,
            );
        }    

        $image = WideImage::load($file_name);

        var_dump($image);

        $resizedImage = $image->resize(639, 554)->saveToFile( 'uploads/' . time() . '_small' . $ext );

        $thumb = 'uploads/' . time() . "_thumb" . $ext;

        $data[] = array(
            'thumb' => $thumb
        );

        $this->session->set_userdata('thumb', $thumb);
        $resizedImage = $image->resize(566, 566)->saveToFile($thumb);

        echo json_encode($data);

    }

I works perfectly for files smaller than 2 MB. But when i upload images greater than 2 MB it didn't work. I dump $image object created it returns nothing.

The image is uploading perfectly uploading to the server but not resizing. Pls suggest solution to it.

I am using this image library http://wideimage.sourceforge.net/

php.ini settings are

post_max_size = 32MB;
upload_max_size = 32MB;
max_execution_time = 300;
max_input_time = 100;

Edit: Image is perfectly uploading to the server problem arise only in resizing when file size is greater than 2 MB.

When file size is smaller than 2MB var_dump($image) outputs

object(WideImage_TrueColorImage)[16]
  protected 'handle' => resource(48, gd)
  protected 'handleReleased' => boolean false
  protected 'canvas' => null
  protected 'sdata' => null

while when greater than 2MB it returns nothing

2
  • Your title still says 'upload error', and 'it didn't work' is not an adequate problem description. Commented Jan 29, 2015 at 6:49
  • @HoboSapiens updated title Commented Jan 29, 2015 at 6:54

3 Answers 3

1

You should check your configuration:

PHP change the maximum upload file size

My guess is you left the defaults and uploads only up to 2MB are allowed.

Sign up to request clarification or add additional context in comments.

Comments

1

If image is uploading perfectly to the server but not resizing - check memory_limit in php.ini (or .htaccess) and try to increase it.

1 Comment

Increasing memory_limit (changed from 16MB -> 128MB; my uploaded img size: 3.6MB) was the solution in my case. Thx
0

Your php.ini is restricting max file size. Change it modifying php.ini values:

; Maximum allowed size for uploaded files.
upload_max_filesize = 400M

; Must be greater than or equal to upload_max_filesize
post_max_size = 400M

1 Comment

You don't need to put ridiculous values like 400MB for this purpose. For images, 5MB should be sufficient.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.