TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Uploading images works for me but not others (http://www.talkphp.com/general/2246-uploading-images-works-me-but-not-others.html)

Orc 02-14-2008 12:46 AM

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.

Alan @ CIT 02-14-2008 12:52 AM

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

Orc 02-14-2008 12:54 AM

Quote:

Originally Posted by Alan @ CIT (Post 10715)
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);

                } 


Alan @ CIT 02-14-2008 12:57 AM

Come on Orc, give us a clue :-D

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

Orc 02-14-2008 01:01 AM

Quote:

Originally Posted by Alan @ CIT (Post 10718)
Come on Orc, give us a clue :-D

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.

Alan @ CIT 02-14-2008 01:09 AM

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

Orc 02-14-2008 01:11 AM

Quote:

Originally Posted by Alan @ CIT (Post 10722)
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 >.<

Alan @ CIT 02-14-2008 01:17 AM

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

Orc 02-14-2008 01:19 AM

Quote:

Originally Posted by Alan @ CIT (Post 10725)
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.

Alan @ CIT 02-14-2008 01:29 AM

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

Orc 02-14-2008 01:32 AM

Quote:

Originally Posted by Alan @ CIT (Post 10729)
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.

Orc 02-14-2008 03:08 AM

I fixed this problem, it works now, just the substring, went way off and was blank.. It now works for others.

xenon 02-15-2008 07:34 PM

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, '.');

Orc 02-15-2008 11:24 PM

Quote:

Originally Posted by xenon (Post 10823)
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.


All times are GMT. The time now is 05:14 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0