是的我有一個PHP內存的問題。我的主人提供最大值。使用64M的內存限制,不知何故,當我上傳+裁剪功能超過這個內存,並IM即時接收錯誤(並不總是,但取決於圖像的大小)PHP:處理內存和代碼的低內存使用率
當我上傳一個約1 MB或更低的圖像,它上傳,您可以裁剪並保存。
但是,當我上傳大約2 MB或更高的圖像(我對uploadfunction的限制是6mb)時,它會上傳,然後當您裁剪圖像並想要保存圖像時,我會收到「內存不足錯誤」。
我試圖在gd中的任何函數之後使用imagedestroy(),我不再使用它,但是這並沒有影響它。雖然即時通訊在功能上只使用GD功能
那麼有沒有什麼能夠在上傳的情況下釋放我的記憶?
或者一般來說如何釋放php內存的使用?
這裏是我的腳本:
switch($action) {
case 'upload':
$userid = $USER;
$user = getUserInfo($userid);
$lasttime = $user['showURP']["photo_lasttime"];
$upload_name = "file";
$max_file_size_in_bytes = 8388608;
$extension_whitelist = array("jpg", "gif", "png", "jpeg");
/* checking extensions */
$path_info = pathinfo($_FILES[$upload_name]['name']);
$file_extension = $path_info["extension"];
$is_valid_extension = false;
foreach ($extension_whitelist as $extension) {
if (strcasecmp($file_extension, $extension) == 0) {
$is_valid_extension = true;
break;
}
}
if (!$is_valid_extension) {
echo "{";
echo "error: 'Filtype not allowed!'\n";
echo "}";
exit(0);
}
/* checking filetype*/
switch(exif_imagetype($_FILES[$upload_name]['tmp_name'])) {
case IMAGETYPE_GIF:
case IMAGETYPE_JPEG:
case IMAGETYPE_PNG:
break;
default:
echo "{";
echo "error: 'This is no real image!'\n";
echo "}";
exit(0);
}
/* file size check */
$file_size = @filesize($_FILES[$upload_name]["tmp_name"]);
if (!$file_size || $file_size > $max_file_size_in_bytes) {
echo "{";
echo "error: 'Filesize exceeds the limit: 6MB'\n";
echo "}";
exit(0);
}
if(isset($_FILES[$upload_name]))
if ($_FILES[$upload_name]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br />";
} else {
$userfile = stripslashes($_FILES[$upload_name]['name']);
$file_size = $_FILES[$upload_name]['size'];
$file_temp = $_FILES[$upload_name]['tmp_name'];
$file_type = $_FILES[$upload_name]["type"];
$file_err = $_FILES[$upload_name]['error'];
$file_name = $userfile;
if(move_uploaded_file($file_temp, "images/profilePhoto/".$file_name)) {
echo "{";
echo "msg: '".$file_name."'";
echo "}";
}
}
break;
case 'crop':
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$jpeg_quality = 90;
$src = "images/profilePhoto/".$_POST['fname'];
$ext= pathinfo($src, PATHINFO_EXTENSION);
if($ext == "jpg" OR $ext == "jpeg" OR $ext == "JPG"){
$img_r = imagecreatefromjpeg($src); // <-- im getting out of memory error on this line
}elseif($ext == "png" OR $ext == "PNG"){
$img_r = imagecreatefrompng($src);
}elseif($ext == "gif" OR $ext == "GIF"){
$img_r = imagecreatefromgif($src);
}
if($_POST['fixed'] == 0) {
$targ_w = $_POST['w'];
$targ_h = $_POST['h'];
}
else {
$targ_h = $_POST['sizeh'];
$targ_w = $_POST['sizew'];
}
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
imagedestroy($img_r); // free memory
$path_thumbs = "images/profilePhoto/thumbs";
$filename = $USER . ".jpg";
$thumb_path = $path_thumbs . '/' . $filename;
imagejpeg($dst_r,$thumb_path,$jpeg_quality);
imagedestroy($dst_r); // free memory
echo json_encode(array(
'filename'=>$thumb_path
));
unlink($src);
}
break;
}
我的主機只支持GD庫用於裁剪圖像,所以可以使用ImageMagick的斜面。
,正如我前面提到的,我的主機有64M一個memory_limit的,是不能被設置
爲什麼-1 ?? ... – Karem 2010-11-12 08:59:56