TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-14-2008, 12:46 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default Uploading images works for me but not others

This is pretty stupid, I have an image upload script, it uploads the images and generated thumbnails, FOR ME, but not for other people. this is too strange to describe, please help. :[

By the way it store those images and thumbnails in a database, well the path.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 12:52 AM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

We'll probably need to see the code before we can help

What do you mean that it works for you but not others? Does it work for anyone? If not, do they get errors?

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-14-2008, 12:54 AM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
We'll probably need to see the code before we can help

What do you mean that it works for you but not others? Does it work for anyone? If not, do they get errors?

Alan
PHP Code:
                if (substr($type,6,12)=="png")
                {
                    list(
$width,$height) = getimagesize($new_path);
                    
$new_w 345;
                    
$new_h 150;
                    
$src_im imagecreatefrompng($new_path);
                    
$dst_im imagecreatetruecolor($new_w,$new_h);


                    
imagecopyresampled($dst_im,$src_im,0,0,0,0,$new_w,$new_h,$width,$height);
                    
imagepng($dst_im$thumb_path);
                } else if (
substr($type,6,12)=="gif")
                {
                    list(
$width,$height) = getimagesize($new_path);
                    
$new_w 345;
                    
$new_h 150;
                    
$src_im imagecreatefromgif($new_path);
                    
$dst_im imagecreatetruecolor($new_w,$new_h);


                    
imagecopyresampled($dst_im,$src_im,0,0,0,0,$new_w,$new_h,$width,$height);
                    
imagegif($dst_im$thumb_path);
                } else if (
substr($type,6,12)=="jpeg")
                {
                    list(
$width,$height) = getimagesize($new_path);
                    
$new_w 345;
                    
$new_h 150;
                    
$src_im imagecreatefromjpeg($new_path);
                    
$dst_im imagecreatetruecolor($new_w,$new_h);


                    
imagecopyresampled($dst_im,$src_im,0,0,0,0,$new_w,$new_h,$width,$height);
                    
imagejpeg($dst_im$thumb_path);

                } 
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 12:57 AM   #4 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Come on Orc, give us a clue

I'm guessing that is your thumbnail code? Is that the part that doesn't work for other users? What does happen? Are you displaying errors, and if so, what errors appear?

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-14-2008, 01:01 AM   #5 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Come on Orc, give us a clue

I'm guessing that is your thumbnail code? Is that the part that doesn't work for other users? What does happen? Are you displaying errors, and if so, what errors appear?

Alan

Oh crap, well they say its an invalid image cause I do a sub string split using substr to see if it equals png, gif, or jpeg, if it does then it generates a thumbnail and stores it to the thumbnail path, with that it uploads the image as an md5 hash with the end of the image type ( png, gif, jpeg ).. Thing is, I removed a portion of the code where it checks to see if it is an image, then it worked, but the thumbnails didnt generate, so a logical explanation is the sub string(substr). I tried
PHP Code:
$type=="png" // etc etc 
And yet the thumbnails still didnt generate. so..

You still have to remember, it only works for me, not others.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 01:09 AM   #6 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

What does $type actually contain after you have uploaded a file? Your substr() starts checking at character 6, and returns 12 characters which I'm guessing won't match much.

If $type just contains the file extension (without the .), then substr($type) would do it. If it contains the full filename, then you could use substr($type, -3) to get the last 3 characters of the filename (likely the extension).

Alternativly, use the pathinfo() function on the filename to get the extension:

PHP Code:
$file '/home/www/images/myimage.jpeg';

$fileParts pathinfo($file);

echo 
$fileParts['extension'];

// echo's: jpeg 
Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
The Following User Says Thank You to Alan @ CIT For This Useful Post:
Orc (02-14-2008)
Old 02-14-2008, 01:11 AM   #7 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
What does $type actually contain after you have uploaded a file? Your substr() starts checking at character 6, and returns 12 characters which I'm guessing won't match much.

If $type just contains the file extension (without the .), then substr($type) would do it. If it contains the full filename, then you could use substr($type, -3) to get the last 3 characters of the filename (likely the extension).

Alternativly, use the pathinfo() function on the filename to get the extension:

PHP Code:
$file '/home/www/images/myimage.jpeg';

$fileParts pathinfo($file);

echo 
$fileParts['extension'];

// echo's: jpeg 
Alan
You're a life saver. :D Sorry but the people who NEED it are getting pissed off. :P

Also, its $_FILES['file']['type'], I then take out image/ and use the others.

Update: Now it says invalid image for me >.<
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 01:17 AM   #8 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Can you edit your script and put:

PHP Code:
echo $_FILES['file']['type']; 
So I can see exactly what it contains when you upload an image?

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-14-2008, 01:19 AM   #9 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Can you edit your script and put:

PHP Code:
echo $_FILES['file']['type']; 
So I can see exactly what it contains when you upload an image?

Alan
Well I echo it out with the substr and it doesn't show. By the way it works for me now cause I was clueless and forgot to do $var['extension'] xD

Update: $var['extension'] doesn't show the image type either.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 01:29 AM   #10 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Can you just echo it out once for me as a test so I can see exactly what the string contains? Once we know what it contains then we can figure out how to get what you need.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-14-2008, 01:32 AM   #11 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Can you just echo it out once for me as a test so I can see exactly what the string contains? Once we know what it contains then we can figure out how to get what you need.

Alan
It won't show up. :/ I uploaded the file and everything, the extension won't show up. Though it works for me not others. >.< they get invalid image, I get successfully uploaded file. its one weird bug.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 03:08 AM   #12 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

I fixed this problem, it works now, just the substring, went way off and was blank.. It now works for others.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-15-2008, 07:34 PM   #13 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

If you want to get the file extension, assuming that your file extension sits at the end of the file name, you can use this function, instead of limiting the file extension to 3 characters (see .jpeg files, .ko files for example):

Code:
$extension = strrchr($file_name, '.');
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-15-2008, 11:24 PM   #14 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
If you want to get the file extension, assuming that your file extension sits at the end of the file name, you can use this function, instead of limiting the file extension to 3 characters (see .jpeg files, .ko files for example):

Code:
$extension = strrchr($file_name, '.');
I have that for my file name to hash up using md5() and then I used that to get the extension. :] But thanks anyway, I might just try it.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:49 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design