问题描述
我创建了一个页面,可以将文件上传到“/storage/app/public/uploads”。我有一个下载按钮,它在我的 XAMPP 测试环境中运行良好。当我将项目上传到服务器时,我仍然可以上传文件。它们也转到同一目录“/storage/app/public/uploads”。但是当我想下载它们时,下载路径是 /storage/uploads/ 并且我收到 404 错误。但这也在我的 XAMPP 上。 在我的 /config/filesystems.PHP 我有 '磁盘' => [
'local' => [
'driver' => 'local','root' => storage_path('app'),],'public' => [
'driver' => 'local','root' => storage_path('app/public'),'url' => env('APP_URL').'/storage','visibility' => 'public','links' => [
public_path('storage') => storage_path('app/public'),
]
我不知道出了什么问题,因为在我的 XAMPP 上它很好。有什么想法吗?
解决方法
在服务器上运行 php artisan storage:link
来修复它。
例如你能不能创建一个新的控制器,
<a hrfe="{{route('downloadfile1')}}">download</a>
public function downloadfile1(){
$file=public_path()."/file1.pdf";
$headers = array(
'Content-Type: application/pdf',);
return Response::download($file,'filename.pdf',$headers);
}