laravel 5 - FileNotFoundException in File.php line 41 -
in laravel making application uploads file , user can download same file.
but each time click download error.
the view code:
<h5><a href="/download/{{$filesharing->filename}}/{{$filesharing->filetype}}">download</a></h5>
the route code:
route::get('/download/{filename}/{filetype}', 'filesharingscontroller@download');
the controller code:
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); }
please not when upload file remove extension. example: if upload 'sample.pdf'
saved 'sample'
.
i have no clue wrong path in error correct path. , file exists in path. plz help
and code used upload file is:
// 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); }
your $downloadpath missing file extension. second parameter of response::download file name shown user.
your variable should this:
$downloadpath = public_path() . '/assets' . $filename . '.' . $filetype;
Comments
Post a Comment