How to allow only files with a specific extension to be downloaded

Hi,

I am having trouble in coding a script. I need only a specific file type to be downloadable. I dont know how to check the file type using PHP. I have the script ready for downloading any file type, but now I need to add a filter which allows only certain file types to be downloadable which I have specified in the code.

Here is the code:

http://www.pasteit.in/126

Please look at the code and advise.

Thank you.

Your paste bin code fails because you cannot put HTML in the PHP header tag, though it’s a nice try and shows that you are thinking.

The way to do it is by using the .htccess file to redefine what the webserver is supposed to with with a file.

Try this http://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/

Another thing you need to think about is what are you going to do if someone renames a file to change the extension such that the file content is not of the type identified by the extension?

Check This Out: http://stackoverflow.com/questions/1232769/how-to-get-the-content-type-of-a-file-in-php

This maybe useful to find out file’s mimetype. It’s also very easy.