doutu7123 2016-09-15 18:36
浏览 77
已采纳

使用slim和php访问目录root之外的文件

Currently my file structure is as follows:

├── README.md
├── app
├── classes
├── composer.json
├── composer.lock
├── database
├── public
├── templates
├── users
└── vendor

Inside of the users folder I have folders that relate to the username of the logged in user, each with their own files and folders defined by the user.

The issue I'm encountering is that I am unable to download files inside the users directory. Currently, I have my code working by moving the users directory inside of the public directory but there are pretty obvious security flaws to this. How would I make it so my users directory is one level up from the root as shown here but still able to be accessed by the public directory?

I've already tried using RewriteRule users/ ../users/ but it does not seem to work. I'm able to access the users directory through PHP, just not my front-controller in the public folder.

This is my first "real" project using Slim so I'm very new to this whole front-controller/mvc type thing. Any help would be great, thanks!

  • 写回答

1条回答 默认 最新

  • douhu2898 2016-09-15 18:53
    关注

    In your routing logic or controller you'd need to verify the user has access to said file, then most likely use PHP to serve the file since it isn't accessible in the web path.

    In PHP, you can set the proper HTTP headers and use readfile() to serve files to the end user.

    http://php.net/manual/en/function.readfile.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部