文件上传后的图像处理会导致此错误:
第 61 行 .. 中允许的内存大小为 67108864 字节已用尽(尝试分配 20624 字节)
第 61 行是:
$imagem = imagecreatefromjpeg($plik);
服务器内存限制设置为 32MB。
我写了这样的代码:
<?php
$user = $_POST['user_name'];
$pass = $_POST['pass'];
$file = $_FILES['file']['tmp_name'];
if ($user == "myuser" && $pass == "mypassword")
{
$directory='grafika/small';
$dir=opendir($directory);
$U = 1;
while($file_name=readdir($dir))
{
if(($file_name!=".")&&($file_name!=".."))
{
$U += 1;
}
}
closedir($dir);
//------------------
//------
list($width, $height) = getimagesize($file);
$new_height_d = 600;
$percent_d = $height / 600;
$new_width_d = $width / $percent_d;
if ($new_width_d > 1100){
$percent = $new_width_d / 1100;
$new_width_d = 1100;
$new_height_d = $new_height_d/ $percent;
}
$percent_m = $height / 113;
$new_width_m = $width / $percent_m;
$image_d = imagecreatetruecolor($new_width_d, $new_height_d);
$image_m = imagecreatetruecolor($new_width_m, 113);
$imaged = imagecreatefromjpeg($plik);
$imagem = imagecreatefromjpeg($plik);
imagecopyresampled($image_d, $imaged, 0, 0, 0, 0, $new_width_d, $new_height_d, $width, $height);
imagejpeg($image_d,'grafika/big/'.$U.'.JPG');
imagecopyresampled($image_m, $imagem, 0, 0, 0, 0, $new_width_m, 113, $width, $height);
imagejpeg($image_m,'grafika/small/'.$U.'.JPG');
//--------------------
//
$do_zapis =' <img class="mini" src="./grafika/small/'.$U.'.JPG" onClick="wys_big(\''.$U.'\')" alt="zaklin"/>';
$file = "subpages/min_lista.html";
$f = fopen($file, "a");
flock($f, 2);
fwrite($f, $do_zapis);
flock($f, 3);
fclose($f);
//-------------
echo('ok');
}
else{
echo('not ok');
}
header("Refresh: 2; URL=edycja.php");
?>
当我尝试在服务器上运行它时,上传 *.jpg 文件(小于 1MB)会出现错误(见上文)。
所以我在想有什么办法可以减少消耗的内存,或者这可能是正常的?