Cody
Cody

Reputation: 2649

php resize function not working when file greater than 2 MB

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

Upvotes: 0

Views: 1463

Answers (3)

Somerussian
Somerussian

Reputation: 391

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

Upvotes: 1

Justinas
Justinas

Reputation: 43479

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

Upvotes: 0

MaGnetas
MaGnetas

Reputation: 5108

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.

Upvotes: 1

Related Questions