Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image type question... 2

Status
Not open for further replies.

wraygun

Programmer
Dec 9, 2001
272
US
I'm using the following portion of a conditional statement to validate valid image types. I'm uploading the file to my server.

I'm using this for gif's and it works great:
Code:
if (($_FILES["file"]["type"] == "image/gif"))

but if I use this for jpeg's, it doesn't work:
Code:
if (($_FILES["file"]["type"] == "image/jpeg"))

Why is the second one failing? I know I'm uploading a valid jpeg, but it doesn't get past this line. odd.

Thanks and best regards,
Harold

***You can't change your past, but you can change your future***
 
I've seen two content-types for JPEG graphics: image/jpeg and image/jpg.

Do a

print $_FILES["file"]["type"];

and find out what your system produces.


Want the best answers? Ask the best questions! TANSTAAFL!
 
Or, if there's 2 known forms of jpeg, why not just do this...

if (($_FILES["file"]["type"] == "image/jpeg")||($_FILES["file"]["type"] == "image/jpg"))

 
Thanks for your responses. I appreciate the tip on printing the file type. That worked well. The type I received was image/pjpeg. Can I expect that to be consistent for all jpegs on this system? Or is there something special about this jpeg?

I should probably do as ID10T16 suggested just to make sure I catch all variations. Does the ||operator represent OR?

Thanks again for your help.

Harold

***You can't change your past, but you can change your future***
 
Yes, as the PHP online manual documents, the "||" operator is logical OR.

A PJPEG is probably a progressive JPEG. But a quick check on the internet brings up that IE version 6 seems to think all JPEGs have the MIME type image/pjpeg. Are you using Internet Explorer?


Want the best answers? Ask the best questions! TANSTAAFL!
 
I am using Internet Explorer. A quick test with Firefox returned image/jpeg. I suppose I should check for all three possiblities. :)

Once again, I appreciate your help.

Best regards,
Harold

***You can't change your past, but you can change your future***
 
I think perhaps a better way is to check the MIME-type on the server side. We already have three possible MIME types -- chasing other variations from other browsers can be difficult and can cause hard-to-diagnose errors.

Depending on your configuration and version, you might have mime_content_type() or the PECL extension Fileinfo


Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks again... :) I'll look into that and learn that as well. BTW, the CSS stuff is working great.

Best regards,
Harold

***You can't change your past, but you can change your future***
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top