Knowledgebase

Serving Files with PHP

Posted by Adam Hallett, 12-24-2007, 10:53 PM
I want to restrict access to particular files. These are large 200 megabyte+ files. Therefore these two approaches are impractical: 1) redirecting to the files (I don't want others viewing them or hotlinking to them) 2) buffering the files with php (kill the webserver in a matter of minutes) Suggestions?

Posted by Barti1987, 12-24-2007, 11:17 PM
Limit access to 1 IP per user using http mod. Peace,

Posted by Adam Hallett, 12-24-2007, 11:26 PM
That would not prevent users from downloading content that I had not approved.

Posted by Barti1987, 12-24-2007, 11:34 PM
Use htaccess file user system (more like password protected directories). Peace,

Posted by Adam Hallett, 12-25-2007, 12:06 AM
How would I allow a specific IP to access a file with htaccess?

Posted by Adam-AEC, 12-25-2007, 11:37 AM
You will most likely want to look into using X-Sendfile. Put the files behind some sort of auth scheme (PHP or BASIC AUTH), and then just send the X-Sendfile header along to your server (Apache/Lighttpd). mod_xsendfile documentation (and example!) is here: http://tn123.ath.cx/mod_xsendfile/

Posted by Adam Hallett, 12-28-2007, 04:16 PM
Is there a way to implement that in PHP without the mod?

Posted by Adam Hallett, 12-28-2007, 04:26 PM
http://blog.thinkphp.de/archives/136...very-easy.html

Posted by Aaron700, 12-28-2007, 07:59 PM
you chould chmod it using your ftp, right click on the folder where these files are and click properties, then it will say : and make it look like : and that should work

Posted by foobic, 12-29-2007, 12:44 AM
Keep the actual files in a location that's not web-accessible and use temporary symlinks to permit downloads. ie. When an authenticated / authorized person clicks the download link, run a PHP script that: 1. creates a new symlink in a web-accessible location with a long, random name. 2. redirects the visitor to that new "file". Then at intervals, delete old symlinks to prevent hotlinking / sharing.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
MySQL Status, help! (Views: 561)
Lowest Hosting Down??? (Views: 663)
Billing software (Views: 638)


Language:

Client Login

Email

Password

Remember Me

Search