Trying to access mp3 files stored outside webroot using cakephp
I have a website that streams mp3 files. All mp3's are currently stored in a files folder in webroot. The problem I have is that anyone with basic web knowledge can download these mp3 files, so I want to store them in a folder outside the webroot, but I dont know how to access the files and stream them if they are stored out there with cakephp. how can i access these files for streaming? or a better solution will be if someone knew a way i could prevent people downloading the files even though开发者_运维问答 they are stored in a folder under webroot (maybe using .htaccess rules?).
CakePHP offers a feature called Media Views for this. It is actually a wrapper that delivers the files and helps you get MIME types and other stuff right. In order to restrict access to logged in users you can simply use the Auth mechanisms provided by CakePHP.
You could use htaccess and block access to the mp3-folder. Create an .htaccess
-File in the MP3-Folder with following content:
Order Deny,Allow
Deny from all
That blocks all access via HTTP - PHP can access the files like before.
精彩评论