 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
02-14-2008, 12:46 AM
|
#1 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
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
|
|
|
|
02-14-2008, 12:52 AM
|
#2 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
02-14-2008, 12:54 AM
|
#3 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Alan @ CIT
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
|
|
|
|
02-14-2008, 12:57 AM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
02-14-2008, 01:01 AM
|
#5 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Alan @ CIT
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
|
|
|
|
02-14-2008, 01:09 AM
|
#6 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
|
The Following User Says Thank You to Alan @ CIT For This Useful Post:
|
|
02-14-2008, 01:11 AM
|
#7 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Alan @ CIT
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
|
|
|
|
02-14-2008, 01:17 AM
|
#8 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
02-14-2008, 01:19 AM
|
#9 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Alan @ CIT
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
|
|
|
|
02-14-2008, 01:29 AM
|
#10 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
02-14-2008, 01:32 AM
|
#11 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Alan @ CIT
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
|
|
|
|
02-14-2008, 03:08 AM
|
#12 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
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
|
|
|
|
02-15-2008, 07:34 PM
|
#13 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
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.
|
|
|
|
02-15-2008, 11:24 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by xenon
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
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|