Uploading images using PHP and script memory limit

I am trying to load a JPG image using a PHP script, but the image continues to force my script to time out and die, giving this error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 
2136 bytes) in image.php on line 38

How can I prevent the download if the image is too large, or this error failed?

+3
source share
6 answers

, (heightwidthcolorDepth), , , , , Flash, Java Silverlight, .

, , () getimagesize , .

.

+3

,

php.ini, upload_max_filesize = 10M

, (10k): <input type="hidden" name="MAX_FILE_SIZE" value="10000" />

, , .

+1

script ini_set.

script:

ini_set('memory_limit', '64M');

, . , . , , , , .

+1
$size=filesize($_FILES['image']['tmp_name']);

$_FILES. $size , .

filesize() api: http://php.net/manual/en/function.filesize.php

0

Does this happen with all download attempts regardless of file size? I only encountered such a problem when there was a script error - usually this is a loop that got out of hand.

0
source

Source: https://habr.com/ru/post/1761446/


All Articles