doutu7123 2016-09-16 02: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-16 02: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

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

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏