Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to serve an image on the web without an extension?

Tags:

image

I'm treating all *.jpg files as static, but I need to serve a few dynamically. Can I simply omit the extension so I don't have to get fancy with my url rules? Is it enough to just set the file type in the header?

like image 973
morgancodes Avatar asked Aug 12 '10 00:08

morgancodes


1 Answers

I've never had a problem serving dynamic images with a strange extension or no extension at all. Querystrings are also fine.

It will be enough for the headers to be correct and the binary file correctly formed. When you do this make sure you also set the Content-Disposition to a reasonable file name so people don't try to download your files with crazy querystring names. (Which windows users will be unable to save since they will most likely have a "?" in them.)

like image 131
jwsample Avatar answered Sep 24 '22 22:09

jwsample