<?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_handle0000$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;
?>
PHP experts: could you help me out? - TranceAddict Forums

TranceAddict Forums

TranceAddict Forums (www.tranceaddict.com/forums)
- Chill Out Room
-- PHP experts: could you help me out?


Posted by Lira on Jun-14-2006 05:46:

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


Posted by LeopoldStotch on Jun-14-2006 06:04:

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?


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.


Posted by LeopoldStotch on Jun-14-2006 06:13:

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.


Posted by Lira on Jun-14-2006 07:15:

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.

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?


Posted by pkcRAISTLIN on Jun-14-2006 08:34:

since you made the world cup sigs & this thread illustrates your obvious qualifications, youve just edged out yan as my favourite TA nerd


Posted by Rostros on Jun-14-2006 13:54:

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.


Posted by Lira on Jun-14-2006 17:12:

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.

Yeah, I guess that's what I will end up doing. I don't know whether my mate's server supports this but I've been delaying this for ages because of these bugs

I'm going to give it a shot, cheers
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.

I learned that method from a tutorial, hehe Before trying imagemagick, I'm going to try another way of calling the write functions then, thanks.

Could you send it through yousendit then? That would be easier I guess, wouldn't it? My e-mail is lira dot becape at gmail dot com
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

I'm flattered, Yan rules


Posted by LeopoldStotch on Jun-14-2006 18:09:

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?


1. . yes that is a good image rendering tool .

2. about declaring it twice, i overlooked the fact that you are passing multiple images into this page, which means multiple descriptions. My bad.


Posted by Rostros on Jun-15-2006 11:13:

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


Posted by Lira on Jun-15-2006 14:32:

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

Good idea! Cheers, I'm downloading it as I type


Posted by Lira on Jun-19-2006 21:03:

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.