Problemer med galleri kode
HejJeg har et problem med følgende kode:
// List of our known photo types
$known_photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);
// GD Function List
$gd_function_suffix = array(
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/gif' => 'GIF',
'image/bmp' => 'WBMP',
'image/x-png' => 'PNG'
);
// Fetch the photo array sent by preupload.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the photo caption array
$photo_caption = $_POST['photo_caption'];
$photo_category = $_POST['category'];
$number_of_fields = $_POST['number_of_fields'];
$path = realpath($_SERVER['DOCUMENT_ROOT']) . $settings['galleryImageDir'];
if (empty($photo_category)){
$form_error = $error->form_error($error = 'Du har ikke valgt en kategori');
$this->upload();
return;
}
$photo_category='"'.addslashes($_POST['category']).'"';
foreach($photos_uploaded['error'] as $key=>$error){
if($error!=UPLOAD_ERR_OK){
switch($error){
case UPLOAD_ERR_INI_SIZE:$reason="File Size exceeds server defined size";break;
case UPLOAD_ERR_FORM_SIZE:$reason="File Size exceeds size defined in form";break;
case UPLOAD_ERR_PARTIAL:$reason="Only a part of the file was uploaded";break;
case UPLOAD_ERR_NO_FILE:$reason="No file was uploaded";break;
case UPLOAD_ERR_NO_TMP_DIR:$reason="No temporary directory for file uploads";break;
case UPLOAD_ERR_CANT_WRITE:$reason="File was not written to disk";break;
case UPLOAD_ERR_EXTENSION:$reason="File had a wrong extension";break;
}
$this->output = $error->error('Lykkedes ikke at uploade:'.$photos_uploaded['name'][$key].'<br>Reason:'.$reason);
continue;
}
if($photos_uploaded['size'][$key] <= 0){
continue;
}
if(!array_key_exists($photos_uploaded['type'][$key], $known_photo_types)){
$this->output = $error->error('Ugyldig filtype i blandt de uploadede billeder');
continue;
}
$connector->query('INSERT INTO cms_gallery_photos SET photo_filename="0", photo_caption="'.addslashes($photo_caption[$key]).'",
photo_category="'.addslashes($_POST['category']).'"');
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'][$key];
$extention = $known_photo_types[$filetype];
$filename = $new_id.".".$extention;
$connector->query('UPDATE cms_gallery_photos SET photo_filename="'.addslashes($filename).'" WHERE photo_id="'.addslashes($new_id).'"');
// Store the orignal file
if(!move_uploaded_file($photos_uploaded['tmp_name'][$key], $path . $filename)){
$this->output = $error->error('Failed to permanently save the file.');
continue;
}
// Let's get the Thumbnail size
$size = GetImageSize( $path . $filename );
if($size[0] > $size[1]){
$thumbnail_width = 150;
$thumbnail_height = (int)(150 * $size[1] / $size[0]);
}
else
{
$thumbnail_width = (int)(150 * $size[0] / $size[1]);
$thumbnail_height = 150;
}
// Build Thumbnail with GD 1.x.x, you can use the other described methods too
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = "ImageCreateFrom".$function_suffix;
$function_to_write = "Image".$function_suffix;
// Read the source file
$source_handle = $function_to_read ( $path . $filename );
if(!$source_handle)
{
$this->output = $error->error('Kunne ikke lave source billed');
continue;
}
// Let's create an blank image for the thumbnail
$destination_handle = imagecreatetruecolor( $thumbnail_width, $thumbnail_height );
// Now we resize it
imagecopyresampled( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] );
// Let's save the thumbnail
$function_to_write( $destination_handle, $path."thumbs/tb_".$filename );
ImageDestroy($destination_handle );
//
//Let's make the small images
$size = GetImageSize( $path . $filename );
if($size[0] > $size[1])
{
$small_width = 486;
$small_height = (int)(486 * $size[1] / $size[0]);
}
else
{
$small_width = (int)(486 * $size[0] / $size[1]);
$small_height = 486;
}
// Let's create an blank image for the small
$destination_handle = imagecreatetruecolor( $small_width, $small_height );
// Now we resize it
imagecopyresampled( $destination_handle, $source_handle, 0, 0, 0, 0, $small_width, $small_height, $size[0], $size[1] );
// Let's save the small
$function_to_write( $destination_handle, $path."small/s_".$filename );
ImageDestroy($destination_handle );
$result_final .= "<img src='".$path."tb_".$filename."' /> File ".($key+1)." Added<br />";
$this->output = $this->html->add_complete($result_final, $key);
imagedestroy($source_handle);
Når jeg vil uploade billeder der er over 1600 * 1200, melder den Fatal error: Allowed memory size of.. osv. I kender den sikkert :)
Jeg har prøvet med: ini_set('memory_limit','32M'); i toppen af scriptet, men det virkede helelr ikke.
Hvad kan jeg gøre?
