PHP Laravel:如何限制直接访问laravel中的文件(http://localhost/projectname/public/uploads/sample.pdf) [英] PHP Laravel : How to restrict direct access to files in laravel ( http://localhost/projectname/public/uploads/sample.pdf)

查看:671
本文介绍了PHP Laravel:如何限制直接访问laravel中的文件(http://localhost/projectname/public/uploads/sample.pdf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我是Laravel的新手,所以我在文件系统和安全性方面面临一些问题,我的问题是..

Since I am new to Laravel, I am facing some issues in file system and security concerns, my question is..

如何限制直接访问laravel中的文件( http://localhost/projectname/public /uploads/sample.pdf )

How to restrict direct access to files in laravel ( http://localhost/projectname/public/uploads/sample.pdf)

我不希望用户显示(获取访问权)正在保存文件的文件夹.问题是,如果他显示该文件夹,他将尝试通过它访问其他文件.直接打开文档路径,根据隐私保护点这是不安全的.只是想防止对文件的任何未经授权的访问...!

I don't want the user to show (get the access) of folder where the files are being save. Problem is if he show the folder he will try to access other files via. directly opening the document path, which is not secure as per privacy point. Just want to prevent any unauthorized access to the file...!

任何宝贵的反馈意见都将受到他的高度评价.

Any valuable feedback will he highly appreciated.

推荐答案

将其存储在您的存储目录中,而不是公共目录中.

Store it in your storage directory, not your public directory.

然后提供一个使用文件下载响应的链接: http://laravel. com/docs/5.6/responses#file-downloads ,您可以在其中验证授权.

Then provide a link that uses a file download response: http://laravel.com/docs/5.6/responses#file-downloads, in which you can verify authorization.

禁止在您的公共目录之外进行访问.

Never allow access outside your public directory.

这篇关于PHP Laravel:如何限制直接访问laravel中的文件(http://localhost/projectname/public/uploads/sample.pdf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆