SuPeRfLy
Legacy Member
Ik heb het volgende probleem:
Ik heb een upload script dat voor elke geuploade afbeelding een thumbnail maakt en vervolgens samen met het origineel opslaat met onder een random naam & de naam dan in de database saved.
Alles werkt zoals ik het verwacht maar om een of andere mysterieuze reden worden enkel de eerste 6 afbeelding van elke post behandeld en de rest verdwijnt zonder foutmelding ergens in het niets.
Ik heb al verschillende dingen geprobeerd waaronder:
Hier is de code:
Hij of zij die mij kan zeggen waar het misloopt >>
Ik heb een upload script dat voor elke geuploade afbeelding een thumbnail maakt en vervolgens samen met het origineel opslaat met onder een random naam & de naam dan in de database saved.
Alles werkt zoals ik het verwacht maar om een of andere mysterieuze reden worden enkel de eerste 6 afbeelding van elke post behandeld en de rest verdwijnt zonder foutmelding ergens in het niets.
Ik heb al verschillende dingen geprobeerd waaronder:
- post_max_size verhoogt tot 20M
- memory_limit verhoogt tot 32M
- een bestand van 15M via post geupload (zonder probleem)
- 10 verschillende afbeeldingen geupload met een ander script (zonder probleem)
- :doh:
Hier is de code:
Hij of zij die mij kan zeggen waar het misloopt >>
PHP:
<?php
// database configuration & variable "$images_dir" setting
include("config.inc.php");
// initialization
$result_final = "";
$counter = 0;
// List of our known photo types
$known_photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
);
// GD Function List
$gd_function_suffix = array(
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
);
// Fetch the photo array sent by preupload.php
$photos_uploaded = $_FILES['userfile'];
// Fetch the photo caption array
$photo_caption = $_POST['photo_caption'];
while( $counter <= count($photos_uploaded) )
{
if($photos_uploaded['size'][$counter] > 0)
{
if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
{
$result_final .= "File ".($counter+1)." is not a photo<br />";
}
else
{
mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = uniqid("")."_1".".".$extention;
mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
// Store the orignal file
copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);
// Let's get the Thumbnail size
$size = GetImageSize( $images_dir."/".$filename );
if($size[0] > $size[1])
{
$thumbnail_width = 250;
$thumbnail_height = (int)(250 * $size[1] / $size[0]);
}
else
{
$thumbnail_width = (int)(250 * $size[0] / $size[1]);
$thumbnail_height = 250;
}
// Build Thumbnail with GD 2.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($images_dir . '/' . $filename);
if ($source_handle) {
// Let's create a 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, $images_dir . '/tb_' . $filename);
//
$result_final .= "<img src='"."http://www.xxxxxxxxxxx.be/processing/photos". "/tb_".$filename."' /> File ".($counter+1)." Added<br />";
}
}
$counter++;
}
// Print Result
echo <<<__HTML_END
<html>
<head>
<title>Photos uploaded</title>
</head>
<body>
$result_final
</body>
</html>
__HTML_END;
?>