<?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

Become a part of the TranceAddict community!Frequently Asked Questions - Please read this if you haven'tSearch the forums
TranceAddict Forums > Main Forums > Chill Out Room > PHP experts: could you help me out?
  Last Thread   Next Thread
Share
Author
Thread    Post A Reply
Lira
Ancient BassAddict



Registered: Nov 2001
Location: Brasilia, Brazil
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


___________________
Indiana Clones Upcoming Sets
[ I May Upload Something Someday ]

Old Post Jun-14-2006 05:46  Brazil
Click Here to See the Profile for Lira Click here to Send Lira a Private Message Visit Lira's homepage! Add Lira to your buddy list Report this Post Reply w/Quote Edit/Delete Message
LeopoldStotch
Suapremae tranecadictt



Registered: Jan 2005
Location: Yawbs,Giaks,and Automobiles
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.


___________________

Old Post Jun-14-2006 06:04  United States
Click Here to See the Profile for LeopoldStotch Click here to Send LeopoldStotch a Private Message Visit LeopoldStotch's homepage! Add LeopoldStotch to your buddy list Report this Post Reply w/Quote Edit/Delete Message
LeopoldStotch
Suapremae tranecadictt



Registered: Jan 2005
Location: Yawbs,Giaks,and Automobiles

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.


___________________

Old Post Jun-14-2006 06:13  United States
Click Here to See the Profile for LeopoldStotch Click here to Send LeopoldStotch a Private Message Visit LeopoldStotch's homepage! Add LeopoldStotch to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Lira
Ancient BassAddict



Registered: Nov 2001
Location: Brasilia, Brazil
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?


___________________
Indiana Clones Upcoming Sets
[ I May Upload Something Someday ]

Old Post Jun-14-2006 07:15  Brazil
Click Here to See the Profile for Lira Click here to Send Lira a Private Message Visit Lira's homepage! Add Lira to your buddy list Report this Post Reply w/Quote Edit/Delete Message
pkcRAISTLIN
arbiter's chief minion



Registered: Jul 2002
Location:

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


___________________

Old Post Jun-14-2006 08:34  Australia
Click Here to See the Profile for pkcRAISTLIN Click here to Send pkcRAISTLIN a Private Message Add pkcRAISTLIN to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Rostros
Carbon Sasquatch



Registered: Dec 2001
Location: United Kingdom

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.


___________________

" You bet your ass we're all alike... we've been spoon-fed baby food at school when we hungered for steak... the bits of meat that you did let slip
through were pre-chewed and tasteless. We've been dominated by sadists, or ignored by the apathetic. The few that had something to teach found us will-
ing pupils, but those few are like drops of water in the desert."

Old Post Jun-14-2006 13:54  United Kingdom
Click Here to See the Profile for Rostros Click here to Send Rostros a Private Message Add Rostros to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Lira
Ancient BassAddict



Registered: Nov 2001
Location: Brasilia, Brazil

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


___________________
Indiana Clones Upcoming Sets
[ I May Upload Something Someday ]

Old Post Jun-14-2006 17:12  Brazil
Click Here to See the Profile for Lira Click here to Send Lira a Private Message Visit Lira's homepage! Add Lira to your buddy list Report this Post Reply w/Quote Edit/Delete Message
LeopoldStotch
Suapremae tranecadictt



Registered: Jan 2005
Location: Yawbs,Giaks,and Automobiles
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.


___________________

Old Post Jun-14-2006 18:09  United States
Click Here to See the Profile for LeopoldStotch Click here to Send LeopoldStotch a Private Message Visit LeopoldStotch's homepage! Add LeopoldStotch to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Rostros
Carbon Sasquatch



Registered: Dec 2001
Location: United Kingdom

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


___________________

" You bet your ass we're all alike... we've been spoon-fed baby food at school when we hungered for steak... the bits of meat that you did let slip
through were pre-chewed and tasteless. We've been dominated by sadists, or ignored by the apathetic. The few that had something to teach found us will-
ing pupils, but those few are like drops of water in the desert."

Old Post Jun-15-2006 11:13  United Kingdom
Click Here to See the Profile for Rostros Click here to Send Rostros a Private Message Add Rostros to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Lira
Ancient BassAddict



Registered: Nov 2001
Location: Brasilia, Brazil

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


___________________
Indiana Clones Upcoming Sets
[ I May Upload Something Someday ]

Old Post Jun-15-2006 14:32  Brazil
Click Here to See the Profile for Lira Click here to Send Lira a Private Message Visit Lira's homepage! Add Lira to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Lira
Ancient BassAddict



Registered: Nov 2001
Location: Brasilia, Brazil

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!


___________________
Indiana Clones Upcoming Sets
[ I May Upload Something Someday ]

Old Post Jun-19-2006 21:03  Brazil
Click Here to See the Profile for Lira Click here to Send Lira a Private Message Visit Lira's homepage! Add Lira to your buddy list Report this Post Reply w/Quote Edit/Delete Message

TranceAddict Forums > Main Forums > Chill Out Room > PHP experts: could you help me out?
Post New Thread    Post A Reply

 
Last Thread   Next Thread
Click here to listen to the sample!Pause playback||||| Another Track 2 Id ||||| [2004] [0]

Click here to listen to the sample!Pause playbackJonas Steur - "Castamara" [2005]

Show Printable Version | Subscribe to this Thread
Forum Jump:

All times are GMT. The time now is 21:30.

Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
HTML code is ON
vB code is ON
[IMG] code is ON
 
Search this Thread:

 
Contact Us - return to tranceaddict

Powered by: Trance Music & vBulletin Forums
Copyright ©2000-2026, Jelsoft Enterprises Ltd.
Privacy Statement / DMCA
Support TA!