<?php
include("config.inc.php");
// initialisation
$result_final = "";
$counter = 0;
// List of 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'];
// Fetch the photo caption array
$photo_description = $_POST['photo_description'];
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";
}
else
{
mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_description`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($photo_description[$counter])."', '".addslashes($_POST['category'])."')" );
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $new_id.".".$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 = 100;
$thumbnail_height = (int)(100 * $size[1] / $size[0]);
}
else
{
$thumbnail_width = (int)(100 * $size[0] / $size[1]);
$thumbnail_height = 100;
}
// Resizing with GD 2.x.x
$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 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, $images_dir."/tb_".$filename );
ImageDestroy($destination_handle );
//
$result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added";
}
}
$counter++;
}
// Print Result
echo <<<__HTML_END
<html>
<head>
<title>Look, it worked!</title>
</head>
<body>
$result_final
</body>
</html>
__HTML_END;
?>
TranceAddict Forums (www.tranceaddict.com/forums)
- Chill Out Room
-- PHP experts: could you help me out?
PHP experts: could you help me out?
After spending nights awake trying to find out what's wrong, I decided to ask you guys for help...
... this is from a gallery I'm developing for a friend of mine. He sends the pictures through a form and this script should take care of them.
However, for some reason I can't understand, the thumbnails are always on 256 colours (and I've used imagecreatetruecolor) and the descriptions disappear. Why?
PHP:
Thanks guys
Re: PHP experts: could you help me out?
| quote: |
| Originally posted by Lira After spending nights awake trying to find out what's wrong, I decided to ask you guys for help... ... this is from a gallery I'm developing for a friend of mine. He sends the pictures through a form and this script should take care of them. However, for some reason I can't understand, the thumbnails are always on 256 colours (and I've used imagecreatetruecolor) and the descriptions disappear. Why? |
reference
here you go. Some documentation on the Perl copy() function, and how at times it does not preserve the file attributes. According to the page, there are different ways to copy files. Hope this helps.
Re: Re: PHP experts: could you help me out?
| quote: |
| Originally posted by LeopoldStotch nice concept. Thumbs up to you. As for your problems, multiple issues could be at fault for the results you are getting. if your thumbnails are in 256 colors, i don't think this is a PHP issue, but rather than a system issue. Check to make sure your system has the correct display settings, etc . Since you are storing the files outside of MySQL by using the file system to save the pictures, this is a seperate issue outside of PHP/MySQL. Another issue could be the copy() function from Perl. I think Perl has a more complex function for copying complex binary files from one area to another area . Check the documentation. As for the lost description, why do you need to call addslashes() to add to the SQL statement ? Is there some special notation you are trying to setup ? If that's not the problem, there's always the issue that you have 'photo_desciption' declared twice. Check that too. Good luck. |

since you made the world cup sigs & this thread illustrates your obvious qualifications, youve just edged out yan as my favourite TA nerd 
Just Install Imagemagick on your Server, it is available for WIN32 and UNIX servers and it is Free, it has many functions for .PHP Image processing and uses a lot less resources.
Thanks for your replies 
| quote: |
| Originally posted by Rostros Just Install Imagemagick on your Server, it is available for WIN32 and UNIX servers and it is Free, it has many functions for .PHP Image processing and uses a lot less resources. |


| quote: |
| Originally posted by Rostros Agreed, I'm using perlmagick to do background image processing on a site I am working on and it works wonders... BUT A lot of shared hosting dont have the php extension of imagemagick installed so GD is the only way to go. Thats a pretty creative way of calling the write functions too.... but I don't know why its doing 256 colors if you are using ImageCreateTrueColor(). Try not calling the image write functions the way you do (as in use the direct imageJPG or imagePNG etc functions) and see if for some reason GD just dosn't like being called that way. You know I have written two different image gallery scripts. My older one, Mobile, seems to be very similiar to this if you would like to see the code for it I can post up a zip of the source sometime. I think its under as MIT License (very similiar to a BSD Liscense) so you can use the code however you want. |
Before trying imagemagick, I'm going to try another way of calling the write functions then, thanks.
| quote: |
| Originally posted by pkcRAISTLIN since you made the world cup sigs & this thread illustrates your obvious qualifications, youve just edged out yan as my favourite TA nerd |
Re: Re: Re: PHP experts: could you help me out?
| quote: |
| Originally posted by Lira Thanks ![]() Anyway, the problem of using Perl in this case is that I don't know anything about it, and learning a whole new language because of a bug sounds a bit drastic, doesn't it? As for the description, I used addslashes() for security measures, although I now realise it might not be necessary in this case, as you pointed out. And about declaring it twice, don't I need to do that in order to create the array? |
Look at coppermine gallery , its Open Source and is amazing it has a awesome support forum aswell with lots of mods etc. It would save you hours of pain free coding. It supports GD 2x and Imagemagick.
Coppermine
| quote: |
| Originally posted by Rostros Look at coppermine gallery , its Open Source and is amazing it has a awesome support forum aswell with lots of mods etc. It would save you hours of pain free coding. It supports GD 2x and Imagemagick. Coppermine |
What the hell?! I looked it all up in coppermine and tested the same code in my computer and it worked. I test it on my server and the problem is there. How can it be? Here's a comparison of a thumbnail here and a thumbnail there:


I can't believe I wasted a whole year in a problem that wasn't a problem in the code
Has this ever happened to any of you? I'm sending an e-mail, raaar!
Powered by: vBulletin
Copyright © 2000-2021, Jelsoft Enterprises Ltd.