Tjenare
Har fått lite problem med minnet på servern när jag laddar upp och skalar om bilder. Allt funkar kanon med bilder i storleksordningen upp till 10-12MP, men sen blire Fatal Error: Allowed memory size of x bytes exhausted.
Kör idag 64MB på servern, och det är vad jag max får använda mig av.
Kod enligt följande:
<?php
mkdir ("../img/news/".$_SESSION['date']."_".$_SESSION['news_id'], 0755, true);
$file_count = count($_FILES['ufile']['name']);
for ($i=0; $i<$file_count; $i++) {
if($_FILES['ufile']['error'][$i] == 0){
$path=("../img/news/".$_SESSION['date']."_".$_SESSION['news_id'].'/'.$_FILES['ufile']['name'][$i]);
$pathcrop=("../img/news/".$_SESSION['date']."_".$_SESSION['news_id'].'/');
copy($_FILES['ufile']['tmp_name'][$i], $path);
chmod($path, 0755);
$filename = $path;
$fileout = $path;
$width = 640;
$height = 480;
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $fileout, 80);
imagedestroy($image);
echo "<a href=step4.php?path=$pathcrop&filename=".$_FILES['ufile']['name'][$i]."'><img src=\"$path\" width=\"150\" height=\"113\" border=\"0\"> </a>";
unset($path,$pathcrop,$filename,$fileout,$width,$height,$radio_orig,$width_orig,$height_orig,$image_p,$image);
}
}
?>
Finns det något sätt att optimera på så användarna kan ladda upp stora filer utan att manuellt behöva skala ner dom?