2
votes

I'm trying to upload image to my localhost right now. It had no problem, If it's a small image(Not over 1 MB). But when i try uploading about 3MB Image. Php said

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 18048 bytes) in C:\Users\Tharit\Desktop\Work\Pixelbar\Code\ecompro\vendor\intervention\image\src\Intervention\Image\Gd\Decoder.php on line 115

It shouldn't be this much.This is code,in image upload part.

        if (Input::hasFile('profile_picture'))
            {
                $old_profile_pic= $user->profile_pic;
                $profile_picture = Input::file('profile_picture');
                $profile_picture_size=getimagesize($profile_picture);
                if($profile_picture_size[0]>$profile_picture_size[1])
                {
                    $mainside = $profile_picture_size[1];
                    $cordx=($profile_picture_size[0]-$profile_picture_size[1])/2;
                    $cordx=(int) $cordx;
                    $cordy=0;
                }
                else
                {
                    $mainside = $profile_picture_size[0];
                    $cordy=($profile_picture_size[1]-$profile_picture_size[0])/2;
                    $cordy=(int) $cordy;
                    $cordx=0;
                }
                $filename  = time() .$user->id . '.' . $profile_picture->getClientOriginalExtension();
                $path = public_path('img/user/' . $filename);
                Image::make($profile_picture->getRealPath())
                            ->crop($mainside,$mainside,$cordx , $cordy)
                            ->resize(100, 100)
                            ->save($path);
                $user->profile_pic = 'img/user/'.$filename;
                if($old_profile_pic != 'img/user/default_profile.gif')
                    {$imagecheck=1;}
            }
2
I suspect that the problem is in your resizing of the image. If this is using gd, then you need to allow image height x width x 4 bytes of memory for both pre and post resize imagesMark Baker
@MarkBaker you mean pre+post?Expl0de
I mean you need to allow enough memory to have both the full size image and the thumbnail in PHP memory at the same timeMark Baker
The memory usage to create the new image will be much larger then the uploaded images size. Most likely your uploaded image is in a compressed format. When you run this manipulation, it is creating a true color image, so the memory usage will be something like Height * Width * Channels * (magical constant); So its possible that the image you are uploading, once decompressed, takes up a lot more memory then you would expect. The "Magical constant" in this case is 1.7 (taken from php.net/manual/en/function.imagecreatetruecolor.php#99623);StephenMtl
@StephenMtl That's a new thing to me. I should learn more! Thank youExpl0de

2 Answers

1
votes

check your php.ini file for this line

upload_max_filesize=1M

and change it to upload_max_filesize=10M

or change "1M" to any other required file size in MBs

0
votes

There are a number of parameters that you have to set in the php ini to make large file uploads possible. They are:

upload_max_filesize
post_max_size
max_input_time
max_execution_time
memory_limit

You should find helpful comments to set them in the php ini file.

Plus, its a memory error so I think it has nothing to do with file upload. memory_limit should fix it. Try setting memory_limit to -1 to assign unlimited memory and figure out if its really a memory problem.