Memory exhausted error ? Why

Why I am getting this error ? I am uploading an image, and re-sizing it using My link image extension, But the problem, is when i upload images having greater width and height like 7000*4000 it gives me this pathetic error


( ! ) Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 28256 bytes) in G:\www\ba.dev\protected\extensions\image\drivers\Image_GD_Driver.php on line 77

. Below is my model rules.


public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('image, user_id, business_id', 'required'),

			array('user_id, business_id', 'numerical', 'integerOnly'=>true),

			array('image', 'length', 'max'=>45),

			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.

			array('id, image, user_id, business_id', 'safe', 'on'=>'search'),

	 array('image', 'file','types'=>'jpg, gif, png', 'allowEmpty'=>true, 'maxSize'=>5120*3840, 'tooLarge'=>'File has to be smaller than 50MB','safe' => false,'on'=>'insert,update'),


                    );

	}

and below is my controller.


public function actionCreate()

	{

		$model=new BusinessPhotos;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['BusinessPhotos']))

		{

                     $rnd = rand(0, 9999);  // generate random number between 0-9999

  

            $model->attributes = $_POST['BusinessPhotos'];

          if(isset($_POST['business_id']) /*&& isset($_POST['image'])*/) 

          {

                        $model->business_id = $_POST['business_id'];

                        $model->user_id = Yii::app()->user->id;

                        // $model->image = $_POST['image'];

          }

           if(isset($_POST['image']) /*&& isset($_POST['image'])*/) 

          {

                       

                         $model->image = $_POST['image'];

                          echo var_dump($model->image);

          }

	

            $uploadedFile = CUploadedFile::getInstance($model, 'image');

            $fileName = "{$rnd}-{$uploadedFile}";  // random number + file name

            $model->image = $fileName;


           

            if ($model->save()) {

                

                $uploadedFile->saveAs(Yii::app()->basePath . '/../img/' . $fileName);

                 $image = Yii::app()->image->load(Yii::app()->basePath . '/../img/' . $fileName);

                 $image->resize(800, 600);

                $image->save(Yii::app()->basePath . '/../img/' . $fileName);

               

                $this->redirect('/business/addphotossuccess/'.$model->business_id);

            }

        }


        $this->render('create', array(

            'model' => $model,

        ));

	}



Even I upload images greater than 51203840 and less than 70004000 it does not upload image instead of that the page gets refresh.What is my mistake ?

You need to look at your PHP settings. Check to see how much memory you have allocated to the PHP environment. php.ini is your friend.

Look for this entry:




;;;;;;;;;;;;;;;;;;;

; Resource Limits ;

;;;;;;;;;;;;;;;;;;;


max_execution_time = 30 	; Maximum execution time of each script, in seconds

max_input_time = 60	; Maximum amount of time each script may spend parsing request data

memory_limit = 128M      ; Maximum amount of memory a script may consume (8MB)  - THIS IS THE ONE YOU SHOULD INCREASE



For starters change it to something like 512m and restart Apache. See if that fixes it. Remember that image resizing takes up a significant amount of memory.

Hey man what Hodges says is correct, but you also must take a look what you’re trying to achive once you free the app. Limits must be analizes and set depending on many factors you can not know yet. that’s what I’m telling you bro… I hope you got me right…

I personally think it is pathetic to even think about handling a 7000 by 4000 image! :lol:

IMO, your job is to make sure that it can never happen!

Is the size of the image that you want to save in your server about 800 x 600 pixels?

Then you don’t need to accept such a huge image with 7000 x 4000 pixels.

There are image uploading tools that can resize the images on client side. You’d want to try one.

Guys thanks so much for your response, Yes I already Increased the memory limit to 512M and upload_max_file to 500M now I got rid of this error, But when i try to upload a big image even greater than 2 mb, the page just refresh.

Sir, I am already using an extension named "image", the extension, resize images having small dimensions but failed if I upload an image having dimensions 7000*4000

@jacmoe Sir, It is my final year project, and as far as 7000*4000 image is concerned, sir, it is in my project that a user can upload images. so just want to resize the image if a user upload a big or heavy image. This is all I wanted. But the extension is not suppose to be working if i upload heavy images. I even removed the extension and then I upload a image size greater than 2 mb, the page only refresh.What should I do now ? Any idea

It is quite common to disallow the user from even submitting an image of that size.

I am not an expert in this, but there are options - maybe Transloadit? http://transloadit.com/

Or at least find an image uploader that supports client side resizing of images.

This is a quite old SitePoint article about your problems : http://www.sitepoint.com/upload-large-files-in-php/

My Google-foo is weak this evening. :)

Try this: https://github.com/blueimp/jQuery-File-Upload/wiki/Client-side-Image-Resizing

Will try sir, Right now I set max_size in my model’s rules to 800600 so if a user upload an image more than 800600 he will see this message “wrong dimensions, invalid size” :lol: So even he uploads an image of size 6 mb or whatever, the page refresh and he will see my message. No more pain. Thanks sir.