views:

49

answers:

2

I am building a site that is permissions based. The user can add or remove read permissions to the public for pages as well as files.

What is the best way to serve files that are protected, using php? I have seen things like www.mysite.com/download?file=filename.jpg or something like that, but I prefer clean paths.

Also, if my files are not password protected, should I just bypass php, and have Apache serve them directly?

Just looking for the best methods here for both.

A: 

You should use the same format of download.php?file=filename.jpg -- but if you want cleaner URLs you should consider using .htaccess's mod_rewrite to 'pretty' the URLs.

henasraf
I have pretty URLS already using mod_rewrite.
Nic Hubbard
Awesome, so you can mask your file-streaming PHP scripts to look like plain files.
henasraf
Are there any speed issues that I need to be concerned about, with php serving files?
Nic Hubbard
Depends on how much background work you do -- most likely, checking a file's permission (assuming you keep them in a database in this case) will slow it by a few milliseconds at load, but the download itself wouldn't be any slower.
henasraf
A: 

If you can modify the web server configuration a bit, you could make a nice friendly path.

www.mysite.com/download/filename.jpg which then rewrites (mod_rewrite on Apache) to download.php?...

This will give you clean paths and the ability to filter access in PHP.

Jacob

TheJacobTaylor