.htaccess - CakePHP: How to control access to downloadable files -
we're running cakephp 2.3...
we need control access pdf files. example, need users able view/download own pdf not others. admins can view them all. etc.
the first question these files should live within cakephp's directory structure.
we experimented /webroot/files/... appears these publically accessible (ie, can navigate directly file if know full path: www.example.com/files/private.pdf
once files stored in secure location, second question best way handle authorization proper users can access proper files.
it feels cakephp has built in support this, can't find documentation it.
you'll need add .htaccess file in folder wherever keep pdfs deny access them through normal means. deny direct access folder , file htaccess doesn't particularly matter put pdfs, though recommend somewhere in webroot folder, , in own folder.
then, you'll need add function in 1 of controllers display pdf, rather linking it. in cakephp < 2.3, can mediaview class. http://book.cakephp.org/2.0/en/views/media-view.html in newer versions of cakephp, it's sending files. http://book.cakephp.org/2.0/en/controllers/request-response.html#cake-response-file
Comments
Post a Comment