Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vandan's avatar
Level 13

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}

0 likes
10 replies
vandan's avatar
Level 13

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>
Snapey's avatar

is the routing correct? what di you have in web.php?

mushood's avatar

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

1 like
vandan's avatar
Level 13

@mushood ok i check file path is valid so how can my mistake

"/opt/lampp/htdocs/pg_final/pgmanagment/public/PG/doc/"
Snapey's avatar

is it not finding the path to your controller method, or not finding the file?

Its simple to check if it reaches your controller....

1 like
Snapey's avatar

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

1 like
vandan's avatar
Level 13

@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>
1 like
vandan's avatar
vandan
OP
Best Answer
Level 13

@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 or to participate in this conversation.