Hallo Zusammen.
Ich habe da ein Problem mit meinem Fotouploadscript.
Ich bekomme öfter die Fehlermeldung 'Out of memory .....'.
Kann ich in meinem script da was optimieren (Ideal ist es glaub ich nicht):
Der Fehler tritt meist bei 'imagecreatefromjpeg' auf.
Das hochgeladene JPG soll 2 Mal gespeichert werden: 1x 800px und 1x 200px breit .
Bin für jeden Anstoß dankbar.
Ich habe da ein Problem mit meinem Fotouploadscript.
Ich bekomme öfter die Fehlermeldung 'Out of memory .....'.
Kann ich in meinem script da was optimieren (Ideal ist es glaub ich nicht):
Der Fehler tritt meist bei 'imagecreatefromjpeg' auf.
Das hochgeladene JPG soll 2 Mal gespeichert werden: 1x 800px und 1x 200px breit .
PHP:
// Zielverzeichnis
$target_dir = SITE_ROOT .DS. 'public' .DS. $this->upload_dir .DS. $this->gal;
// Verzeichnis erstellen wenn nicht vorhanden
if(!is_dir($target_dir)){
mkdir($target_dir, 0777, true) ;
}
$target_path = SITE_ROOT .DS. 'public' .DS. $this->upload_dir .DS. $this->gal .DS. $this->imagename;
if(file_exists($target_path)) {
$this->errors[] = "Die Datei {$this->imagename} ist schon vorhanden.";
return false;
}
move_uploaded_file($this->source, $target_path);
$imagepath = $this->imagename;
$save = SITE_ROOT .DS. 'public' .DS. $this->upload_dir .DS. $this->gal .DS. $this->filename; // neu
$file = SITE_ROOT .DS. 'public' .DS. $this->upload_dir .DS. $this->gal .DS. $imagepath; // original
list($width, $height) = getimagesize($file) ;
$modwidth = 800;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 90) ;
$save = SITE_ROOT .DS. 'public' .DS. $this->upload_dir .DS. $this->gal .DS. $this->filename2; //neu
$modwidth2 = 200;
$diff2 = $width / $modwidth2;
$modheight2 = $height / $diff2;
$tn2 = imagecreatetruecolor($modwidth2, $modheight2) ;
if(imagecopyresampled($tn2, $image, 0, 0, 0, 0, $modwidth2, $modheight2, $width, $height)){ ;
imagejpeg($tn2, $save, 90) ;
unlink($file);
// Save
if($this->create()) {
unset($this->temp_path);
return true;
}
} else {
$this->errors[] = "Der Dateiupload ist fehlgeschlagen!";
return false;
}
Bin für jeden Anstoß dankbar.