我一直在四处走动.我上传了以下工作:
public function store(Tool $tool)
{
If(Input::hasFile('file')){
$file = Input::file('file');
$name = $file->getClientOriginalName();
$path=Storage::put('public',$file); //Storage::disk('local')->put($name,$file,'public');
$file = new File;
$file->tool_id = $tool->id;
$file->file_name = $name;
$file->path_to_file = $path;
$file->name_on_disk = basename($path);
$file->user_name = \Auth::user()->name;
$file->save();
return back();
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试下载时:
public function show($filename)
{
$url = Storage::disk('public')->url($filename);
///$file = Storage::disk('public')->get($filename);
return response()->download($url);
}
Run Code Online (Sandbox Code Playgroud)
我从laravel获取FileNotFound异常但是,如果我使用它:
$file = Storage::disk('public')->get($filename);
return response()->download($file);
Run Code Online (Sandbox Code Playgroud)
我明白了
File.php第37行中的FileNotFoundException:文件"use calib;
插入笔记(
tool_id,user_id,note,created_at,updated_at)VALUES(1,1, 'Windows Server 2008的吮吸',现在(),现在());"不存在
这是文件的实际内容......
它显然可以找到该文件.但为什么不下载?
Par*_*ras 31
试试这个:
return response()->download(storage_path("app/public/{$filename}"));
Run Code Online (Sandbox Code Playgroud)
代替:
$file = Storage::disk('public')->get($filename);
return response()->download($file);
Run Code Online (Sandbox Code Playgroud)
和:
return response()->download(storage_path('app/public/' . $filename));
Run Code Online (Sandbox Code Playgroud)
response()->download()获取文件的路径,而不是文件内容。更多信息在这里:https : //laravel.com/docs/5.4/responses#file-downloads
| 归档时间: |
|
| 查看次数: |
30156 次 |
| 最近记录: |