Description
How to create download buttons icons in Laravel like the buttons on this site :
https://www.dawateislami.net/bookslibrary/
and the buttons should also download the related file etc pdf , mp4 and mp3 whatever file is attached and the download button is for download
means i want to know the full coding and logic of dowload file button in Laravel not only how to make this button in frontend
Sure, for the downloads, you can add font awesome cdn to get the download icon for the button, and on the button, you can submit a form containing the file name which you want to download so pass it as reference and accept it in the controller.
Controller Login:
public function downloadFile($filename)
{
$filePath = public_path('videos/');
$fileName = 'laravel course intro.mp4';$fileWithPath = $filePath. $fileName;if (!file_exists($fileWithPath)) {abort('404');}return response()->download($fileWithPath);}
Don't remove trailing / after the videos, otherwise it wouldn't work.
1 Like 6 Comments
Hadayat Niazi Super Admin
Nouman Hanif Author
Hadayat Niazi Super Admin
Nouman Hanif Author
i have made a simple html document : <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Download Attribute</title> </head> <body> <a href="CV 29-11-23.pdf" download="">Download CV</a> </body> </html>
Nouman Hanif Author
Hadayat Niazi Super Admin
Nouman Hanif Author
Nouman Hanif Author
In the answer downloadFile($filename) is written , here Inthe $filename variable is used which in not declared before , I will have to declare it myself before and what value I will have to assign , I didn't understand it
Nouman Hanif Author
Nouman Hanif Author
Hadayat Niazi Super Admin
Nouman Hanif Author
Hadayat Niazi Super Admin
Nouman Hanif Author
because i am not expert it takes time to work , i am u can say a beginner in Laravel
Hadayat Niazi Super Admin
Nouman Hanif Author
i had not checked therefore i did not press the solved , I am checking , if the problem solves i tell other i further asks for the problem occuring
Good job @Nouman