首先,我知道有关“memory_limit”错误的这些问题已多次询问,并且大多数解决方案都涉及ini_set修改,但我不认为这是我的情况。
事实上,我正在接受: [2013年4月21日22:21:48 UTC] PHP致命错误:/ home / xxx / public_html / www4 / admincenter / clientes / 102 / slides / nuevo_slide允许的内存大小为52428800字节(试图分配16000字节)第20行的.php
正如您所看到的,允许的总内存大小实际上超过了函数尝试分配的大小,但我仍然收到相同的错误:\ 至于我能够看到imagecreatefromjpeg函数应该存在问题(如错误行所示:20)
这是我的代码: 顺便说一句,它适用于img1而不是img2:
这两个尺寸都在允许的内存下。 我真的很感谢你的帮助。 谢谢!
<?php ini_set("memory_limit", "100M"); ?>
<?php require_once '/home/xxx/private_html/0a/configuration.php';?>
<?php require_once '/home/xxx/private_html/102/configuration.php';?>
<?php
$titulo = ucwords($_POST['titulo']);
$texto = utf8_encode($texto);
$q = "INSERT INTO slides (`id`, `titulo`, `texto`, `fecha`) VALUES (NULL, '".$titulo."', '".$texto."', CURRENT_TIMESTAMP)";
$sql = mysql_query($q);
$id = mysql_insert_id();
for ($i = 1; $i < 3; $i++){
if ($_FILES["foto"]["type"] == "image/jpeg" || $_FILES["foto"]["type"] == "image/pjpeg" ){
if($_FILES["foto"]["type"] == "image/jpeg" || $_FILES["foto"]["type"] == "image/pjpeg"){
$image_source = imagecreatefromjpeg($_FILES["foto"]["tmp_name"]);
}
if ($i == 1){
$max_upload_width = 902;
$max_upload_height = 289;
$remote_file = $sld .$id."_".$max_upload_width."x".$max_upload_height.".jpg";
}
if ($i == 2){
$max_upload_width = 166;
$max_upload_height = 67;
$remote_file = $sld .$id."_".$max_upload_width."x".$max_upload_height.".jpg";
}
imagejpeg($image_source,$remote_file,100);
chmod($remote_file,0755);
// get width and height of original image
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$max_upload_width || $image_height >$max_upload_height){
$proportions = $image_width/$image_height;
if($image_width>$image_height){
$new_width = $max_upload_width;
$new_height = round($max_upload_width/$proportions);
}else{
$new_height = $max_upload_height;
$new_width = round($max_upload_height*$proportions);
}
$new_image = imagecreatetruecolor($max_upload_width , $max_upload_height);
$image_source = imagecreatefromjpeg($remote_file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $max_upload_width, $max_upload_height, $image_width, $image_height);
imagejpeg($new_image,$remote_file,100);
imagedestroy($new_image);
}
imagedestroy($image_source);
}
}
header("Location: index.php?msg=350");
exit();
?>