OctoberCms 查看受保护的文件

OctoberCms viewing protected files

如何在 OctoberCMS 中查看 受保护的 文件?转到其 link 会引发 404 错误。有什么方法可以查看、下载或显示文件吗?

我已经按照手册中的说明上传了文件:

public $attachOne = [
    'resume' => ['System\Models\File', 'public' => false]
];

参考:https://octobercms.com/docs/database/attachments

嗯,实际上你可以 not show 使用 direct URL 那个文件,因为我们知道这是受保护的文件。所以它不能直接从 URL

访问

所以 proper wayread file from diskshow it to user or allow user to download it

October CMS 提供 elegant 方法 echo $file->output();

首先你需要有受保护的文件file IDits relation

然后你可以 defined CMS page 和 url /show-file/:id 将保存 logic 用于显示文件。

此页面将接受 candidate id 作为 id 并将他的 resume 显示给 him/user or allow user to download it

Now in that page code section

use YourPlugin\Models\Candidate;
function onStart() {    

    $candidateId = $this->param('id');

    // do some validation with $candidateId if you really want to show file or not , 
    // may be compare to current login user etc .. here    

    // if all ok then
    $candidate = Candidate::find($candidateId);
    echo $candidate->resume->output();
    exit();

}

echo $candidate->resume->output();add all necessary headers for file 自动并且用户可以查看或下载文件

引用:作者也引用了这个东西https://octobercms.com/forum/post/download-file

如果您发现任何问题,请发表评论。