how to dowload file from laravel blade i try to download particular file to download but when i click to download then whole data as file download not file download so how to download file as particular idwise
here is my blade file
@foreach($doc as $docs)
<a href="#" download="{{$docs->multiple_doc}}">
<img src="{{asset('admin/assets/media/users/doc.png')}}" height="100px" width="100px">
</a>
@endforeach
try to download then output like below
/home/byteandbits/Downloads/{_id__1,_doc_id__1,multiple_doc___usRHurolYBS5iNVnNSmuIhHsd5Y4kg.png ,created_at___2019-12-28 04_19_43 ,updated_at___2019-12-28 04_19_43 }
sorry my past question by mistake i paste
@mushood ok i change but when i click same issue Failed - Server problem like error file not found
public function downloadfile($id)
{
$file = Multipledocument::where('doc_id',$id)->first();
// return $file;
$myfile = public_path('PG/doc/',$file->id,'/',$file->multiple_doc);
return response()->download($myfile);
}
blade file
<a href="{{route('downloadfile',$docs->pg_id)}}" download="">
<img src="{{asset('admin/assets/media/users/doc.png')}}" height="100px" width="100px">
</a>
is the routing correct? what di you have in web.php?
first check the file path
$myfile = public_path('PG/doc/',$file->id,'/',$file->multiple_doc);
dd($myfile);
Then check that the file is actually there or adjust your path accordingly
@mushood ok i check file path is valid so how can my mistake
"/opt/lampp/htdocs/pg_final/pgmanagment/public/PG/doc/"
is it not finding the path to your controller method, or not finding the file?
Its simple to check if it reaches your controller....
@snapey so how can i download correct path file
This
"/opt/lampp/htdocs/pg_final/pgmanagment/public/PG/doc/"
does not look like a full file path? It seems to be missing any filename
@snapey ok sir i check but my path was correct no any file missing
"/opt/lampp/htdocs/pg_final/pgmanagment/public/PG/doc/"
my controller file may be my code was right or any line missing
public function downloadfile($id)
{
$file = Multipledocument::where('doc_id',$id)->first();
// return $file;
$myfile = public_path('PG/doc/',$file->id,'/',$file->multiple_doc);
dd($myfile);
return response()->download($myfile);
}
here is my blade file
<a href="{{route('downloadfile',$docs->id)}}">
<img src="{{asset('admin/assets/media/users/doc.png')}}" height="100px" width="100px">
</a>
@mushood @snapey thank you sir i understand my mistake and solved by myself
actually mistake was i use , sign
$myfile = public_path('PG/doc/',$file->id,'/',$file->multiple_doc);
now
$myfile = public_path('PG/doc/'.$file->id.'/'.$file->multiple_doc);
run perfectally thanks
Please sign in or create an account to participate in this conversation.