19

And the images I'm referring to are the ones that can be embeddable in a web browser not .tif, .psd, etc.

So the only ones I'm aware of are .png / .jpg / .jpeg / .gif / .bmp

are there any more?

Reason why I need this info is to only allow valid images to be uploaded in my php file upload script.

Sam
  • 215
  • 1
  • 2
  • 3
  • 1
    duplicated http://stackoverflow.com/questions/183831/which-graphic-file-formats-are-supported-by-browsers – Skrol29 Apr 07 '11 at 15:07
  • And you expect to be able to do this just by looking at the file extension? – Ignacio Vazquez-Abrams Apr 07 '11 at 15:08
  • Define "a web browser", `bmp` support is far from universal. – Quentin Apr 07 '11 at 15:09
  • 2
    To expand on Ignacio's comment — Do you really trust everybody who might try to upload a file to not be disguising something else with a false file extension and/or mime type? – Quentin Apr 07 '11 at 15:10
  • @Ignacio actually I will be checking the $_FILE[type] returned by PHP, I wrote a small script that shows the type of any file, so to get the needed types I need some test files with the proper extensions. – Sam Apr 07 '11 at 15:22

2 Answers2

4

you can do what ever you like, its all about the headers, and the information inside the actual image that determines the type. (mime-types)

hence why <img href='http://site.com/image.php?name=file'> could actually render an image

dogmatic69
  • 7,574
  • 4
  • 31
  • 49
1

Maybe not a direct answer to this question, but since you mentioned that the purpose of this is to restrict a file upload, the HTML5 answer to this problem would be to use:

<input type="file" accept="image/*">

In addition to that you may also want a server-side check.

In terms of all possible valid image types, there isn't really a simple answer, but most of the information you would need to construct one would be to consult with this list on wikipedia. It of course depends a bit on what the image is going to be used for. The set of images that can be rendered by a browser is going to be different from the set that can be opened in photoshop.

Cory
  • 22,772
  • 19
  • 94
  • 91