1
I need to make PDF files available for download. I don’t know if I’m at least on the right track, but I’m having an error that indicates the file doesn’t exist. My controller is as follows:
public function download($id,Request $request)
{
$title = 'Download - file';
if($request->ajax())
{
return URL::to('file/'. $id . '/download');
}
$file = File::findOrfail($id);
$fileNome = $file->nome;
$dir= public_path()."\\$file->user_id\\$fileNome";
$headers = array(
'Content-Type: application/pdf',
);
$baixar = Response::download($dir, $fileNome, $headers);
return view('file.download',compact('title','baixar'));
}
The mistake is:
Filenotfoundexception in File.php line 37: The file "C: xampp htdocs punctualContabi public 1 boleto_cassio.pdf" does not exist in File.php line 37 at File->__Construct('C: xampp htdocs pointContabi public 1 boleto_cassio.pdf') in Binaryfileresponse.php line 94
The file path is correct. I don’t understand the reason for this error. Can anyone help ?
Take the URL and paste it into the browser. See if it opens the file.
C:\xampp\htdocs\pontualContabi\public\1\boleto_cassio.pdf
– Diego Souza
"File not found". When you paste the direct link into the browser it turns file://C:/xampp/htdocs/pointContabi/public/1/boleto_cassio.pdf
– Juliano Moura
So there is no :p file
– Wallace Maxters
Yes, the file exists. It is in the folder.
– Juliano Moura
Go to his folder through the explorer and see which folder that file really is in. Believe the error. If you’re saying you didn’t find it, it’s because it’s wrong. Click on the address bar in the file folder and copy the address and paste it here.
– Diego Souza
The file is there. Even I use another way to access the file. I do not know if it is indicated for security reasons. I call a modal with the link to the file, so I can. I just don’t know if this way is the right way to accomplish this task.
– Juliano Moura