我有应用程序 Laravel。
路径下有一个存储:\storage\app\reports\
我尝试通过 GET url 获取文件,例如:
http://localhost:8000/storage/app/reports/report_27-05-19_05.xlsx
但这对我不起作用。
我还尝试在后端返回文件:
$file = File::get(storage_path($path.$filename));
$type = File::mimeType($path.$filename);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
最佳答案
尝试这样的事情。
以下示例适用于存储在共享主机中的 csv 文件
$filename
是保存的文件的名称,将通过 get
请求传递
public function download($filename)
{
$name = $filename;
$file = $file = '/home/USERNAME/storage/report/'.$name;
$header = array(
'Content-Type' => 'application/csv',
'Content-Disposition' => 'attachment',
'Content-lenght' => filesize($file),
'filename' => $name,
);
// auth code
return Response::download($file, $name, $header);
}
关于laravel - 如何通过公共(public) URL 从存储中获取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56340029/