![](/img/trans.png)
[英]FileNotFoundException in Filesystem.php line 41: File does not exist at path (LARAVEL)
[英]FileNotFoundException in File.php line 41
在laravel中,我正在制作一个上传文件的应用程序,用户可以下载相同的文件。
视图代码:
<h5><a href="/download/{{$filesharing->fileName}}/{{$filesharing->fileType}}">Download</a></h5>
路线代码:
Route::get('/download/{fileName}/{fileType}', 'FilesharingsController@download');
控制器代码:
public function download($fileName, $fileType){
$downloadPath = public_path(). '/assests/' . $fileName ;
$headers = array(
'Content-Type: application/octat-stream',
'Content-Type: application/pdf'
);
return Response::download($downloadPath, $fileName . '.' . $fileType, $headers);
}
请注意,当我上传文件时,我会删除其扩展名。 示例:如果我上传'sample.pdf'
它被保存为'sample'
。
我不知道出了什么问题,因为错误中的路径是正确的路径。 并且该文件存在于该路径中。 请帮忙
用于上传文件的代码是:
// Save uploaded file
if ($this->request->hasFile('file') && $this->request->file('file')->isValid()) {
$destinationPath = public_path() . '/assests/';
$fileName = $filesharing->fileName . '.' . $this->request->file('file')->guessClientExtension();
$this->request->file('file')->move($destinationPath, $fileName);
}
您的 $downloadPath 缺少文件扩展名。 Response::download 的第二个参数是显示给用户的文件名。
您的变量应如下所示:
$downloadPath = public_path() . '/assets' . $fileName . '.' . $fileType;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.