我可以上传文件,但是当我尝试下载PDF时,它抛出404:找不到页面..我不知道我错在哪里? 我的控制器是:
public function Download(Request $request,$path)
{
$path = public_path("dummy.pdf");
$headers = ['Content-Type: application/pdf'];
$fileName = time().'.pdf';
if (file_exists($path)) {
return Storage::download($path, $fileName, $headers);
} else {
echo('File not found.');
}
}//end of method
路线有:
Route::prefix('admin')->group(function(){
Route::get('/login',[AdminController::class,'Index'])->name('admin_login');
Route::post('/login/owner',[AdminController::class,'Login'])->name('admin.login');
Route::get('/dashboard',[AdminController::class,'Dashboard'])->name('admin.dashboard')->middleware('admin');
Route::get('/Logout',[AdminController::class,'AdminLogout'])->name('admin.logout')->middleware('admin');
/*--------------- File Upload Route---------*/
Route::get('/upload-file', [NoteController::class, 'createForm'])->name('upload-file');
Route::post('/upload-file', [NoteController::class, 'fileUpload'])->name('fileUpload');
Route::get('/notes', [NoteController::class, 'ViewNote'])->name('myNote');
Route::get('/download', [NoteController::class, 'Download'])->name('download');
查看文件是..
<tbody>
@foreach ($notes as $note)
<tr>
<td>{{ $note->path }}</td>
<td>{{ $note->user_type }}</td>
<td> {{ $note->description }}</td>
<td><a href="">View</a></td>
<td><a href="{{ route('download',$note->path) }}">Download</a></td>
</tr>
@endforeach
</tbody>
我通过创建符号链接找到了答案。我使用了以下命令: php artisan storage:link 它对我有用。