douchuanchai2793 2013-07-24 03:58
浏览 12

laravel防止未经身份验证的用户查看文件

I want to try to make some route filter using pattern filter, but it's doesn't work. How to make a route to prevent unauthenticated users from viewing files on specific folder ?

  • 写回答

1条回答 默认 最新

  • dongpang2029 2013-07-24 04:42
    关注

    Try this:

    Route::get('/directory/{file}', array('before' => 'auth', function($file)
    {
        return public_path() . "/directory/$file";
    }));
    

    Change directory to whatever the directory is you are trying to protect. Also, I assumed the files you want to deal out are in your public directory. That may need to be changed too, depending on your usage.

    Auth is a filter that is already created in a default install of Laravel. It just makes sure they aren't a "guest." It will only let people access the directory if they are "logged in." I believe it looks for a cookie that Laravel sets when you log someone in.

    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000