OctoberCms查看受保护的文件

时间:2018-02-25 12:45:18

标签: octobercms

如何在OctoberCMS中查看受保护的文件?转到它的链接会引发404错误。有没有办法查看,下载或显示文件?

我上传的文件就像手册上说的那样:

jrun@notebook-0hnhf:/home/jrun$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _' |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu'

julia> function fun(x::Real, y::Real)
           x, y
       end
fun (generic function with 1 method)

julia> pmap(fun, [x for x = 0:.1:2], [y for y = 4:-.1:2])
21-element Array{Tuple{Float64,Float64},1}:
 (0.0, 4.0)
 (0.1, 3.9)
 (0.2, 3.8)
 (0.3, 3.7)
 (0.4, 3.6)
 (0.5, 3.5)
 (0.6, 3.4)
 (0.7, 3.3)
 (0.8, 3.2)
 (0.9, 3.1)
 (1.0, 3.0)
 (1.1, 2.9)
 (1.2, 2.8)
 (1.3, 2.7)
 (1.4, 2.6)
 (1.5, 2.5)
 (1.6, 2.4)
 (1.7, 2.3)
 (1.8, 2.2)
 (1.9, 2.1)
 (2.0, 2.0)

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

1 个答案:

答案 0 :(得分:1)

嗯,实际上您可以使用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使用网址/show-file/:id来保存logic以显示文件。

此页面将接受candidate id ID ,并将resume显示为him/user or allow user to download it

  

现在在该页面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

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