Create download link for music or video
You can try this. I've tried it, and it's working for me.
<a href="link/to/your/download/file" download> Download link </a>
How can I create download link in HTML?
This answer is outdated. We now have the
download
attribute. (see also this link to MDN)
If by "the download link" you mean a link to a file to download, use
<a href="http://example.com/files/myfile.pdf" target="_blank">Download</a>
the target=_blank
will make a new browser window appear before the download starts. That window will usually be closed when the browser discovers that the resource is a file download.
Note that file types known to the browser (e.g. JPG or GIF images) will usually be opened within the browser.
You can try sending the right headers to force a download like outlined e.g. here. (server side scripting or access to the server settings is required for that.)
Create Download Link Properly
What is the server side language you have?
You need to set the below header from the server response,
Content-Disposition: attachment; filename=SasanKhan-Namoondi[320].mp3;
On the other hand, you can do the same at web server level. For an instance, if you use Apache, you can do this with .htaccess file
<IfModule mod_headers.c>
<FilesMatch "\.(mp3|MP3)$">
ForceType audio/mpeg
Header set Content-Disposition "attachment"
Allow from all
</FilesMatch>
</IfModule>
Also, you have to enable headers module to make this works,
Make sure the below is checked
Apache -> Apache Modules -> headers_module
Download video link
Maybe the download attribute is what you are looking for...
Javascript: Form input audio to audio download link?
the trick is you should just turn it into an ObjectURL
then as the name suggest you can use it as url for href
,
so now been tested on safari, Chrome, FireFox :
var file = element.files[0];
var link = document.getElementById("blah");
link.href = window.URL.createObjectURL(file);
link.download = "someName." + file.name.split(".").pop();
here it's working at PlayCode.io
HTML Link for download mp3 support for website and Android Browser
If you still want to force the browser to download the file, modify the HTTP headers directly. Here's a PHP code example:
$path = "path/to/video.mp4";
$filename = "video.mp4";
header('Content-Transfer-Encoding: binary'); // For Gecko browsers mainly
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Accept-Ranges: bytes'); // Allow support for download resume
header('Content-Length: ' . filesize($path)); // File size
header('Content-Encoding: none');
header('Content-Type: video/mp4'); // Change the mime type if the file is not PDF
header('Content-Disposition: attachment; filename=' . $filename); // Make the browser display the Save As dialog
readfile($path); // This is necessary in order to get it to actually download the file, otherwise it will be 0Kb
Note that this is just an extension to the HTTP protocol; some browsers might ignore it anyway.
Related Topics
How to Apply Mix-Blend-Mode While Keeping Text Opaque
Best Practice for Using Svg Images
How to Make Rounded Border in Ie8 with CSS
Responsive Square Divs Cross Browser Compatible
Make Input Element (Type="Text") Handle Multiple Lines of Text
Relative Urls and Trailing Slashes
Cordova List All Files from Application Directory (Www)
Wget Recognizes Some Part of My Url Address as a Syntax Error
HTML5 Canvas Scrolling Vertically and Horizontally
How to Make a Text Input Non-Editable
How to Display HTML Code (Entities) on a Web Page