1,105,226 Community Members

$_FILES Type field is empty

Member Avatar
msowards
Newbie Poster
1 post since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm trying to allow members to upload a picture to the my website. I In my php code I test the uploaded files for type. For some files it works fine, but I've discovered there are .jpg files that don't seem to have the internal type headers and the php $_FILES array will not have any data in the type variable.

if (($_FILES["$Flnm"]["type"] == "image/gif")
  || ($_FILES["$Flnm"]["type"] == "image/jpg")
  || ($_FILES["$Flnm"]["type"] == "image/png")
  || ($_FILES["$Flnm"]["type"] == "image/jpeg")
  || ($_FILES["$Flnm"]["type"] == "image/pjpeg"))

This is the 'if' test for type, but on some files this variable is blank.
The thing is the files that return a type blank are first download from my Kodak digital camera. However I know that these files are accepted on other web site like Craig's List. So I think there must be a work around.

Member Avatar
ddymacek
Posting Whiz
324 posts since Jun 2010
Reputation Points: 15 [?]
Q&As Helped to Solve: 68 [?]
Skill Endorsements: 0 [?]
 
0
 

So you need to process them a different way. Or decide if you want to accept the file or not. The whole point of checking the file type is to make sure you are getting a specific type of file. So if the image type comes across as blank, save it in a 'safe' folder and perhaps send an email to somebody to verify the image is an image before moving the file into the users account or whatever you are doing.
Or even easier, tell the end user that the file they are trying to upload does not have an image type associated with it. use a photo editor to convert/save the image as a jpg and re-upload. gimp is a free editor. There may be some online tools to convert photos as well.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: