Left click to download mp3 - html

I have searched and can't find a solid answer to this question.
Is it possible to instead of right clicking and saving the file as... Can you instead code it to make it downloadable on left click and also keep it in .mp3 format?

Set the Content-Disposition header to attachment on the server side, when serving the mp3. Something like this:
Content-Disposition: attachment; filename="SloJamz.mp3"
The implementation specifics depend on what server-side language(s)/framework(s) you're using.

it depends on how your app/web server sends this data. in order to download a file directly it should be sent with a
"Content-Disposition: "attachment"
header.

add this line to your .htaccess file
AddType application/octet-stream .mp3

Related

Html download a file that will be generated when the button is clicked

It seems that in html5, you can do download like this:
Download
The path_to_file will be the file you want to download. However, I need to call a back end service(like a HTTP post) first, so that the file will be generated in the first place, then I could download it.
What's the best solution to accomplish this? Adding a listener to the <a tag which triggers a call to back end?
that link should point to a endpoint that generates the file and returns it with a response header Content-Disposition: attachment; filename=your-file.whatever

Create Download Link Properly

I am new at web developing, I was trying to create download link for a file. This is the code:
<a href="http://symphonyrecords.ir/ARTISTS/Sasan-Khan-Namoondi/SasanKhan-Namoondi[320].mp3" target="_blank" download="SasanKhan-Namoondi[320]">
<button class="downBtn1">Download</button></a>
But when I click the link the file starts downloading inside the browsers not in IDM. (I have tested other links from websites and there was no problem). Should I do something in the meta tag or something ?
After one day research and strangling i found the answer ... I just add onclick method and put the file link with www inside windows.open like this :
<a onclick="window.open ('http://www.symphonyrecords.ir/ARTISTS/Sasan-Khan-Namoondi/SasanKhan-Namoondi[320].mp3', ''); return false" href="javascript:void(0);" download>
<button class="downBtn1">Download</button></a>
This is not the best answer but it will do the job
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
You can try this link:-How can I create download link in html?
Your code looks totally fine so it's certainly something with your browser or the download manager.
Have you tried it with another download manager?
Maybe you can give this one a try.

Browsers try to download html file instead of opening

Browsers (Chrome and Safari) Try to download this html file when opened. It is only on that link that it tries to download it. Also note that internet explorer opens it without a problem.
The one thing that I think is causing this may be wordpress or some plugin within wordpress but it seems unlikely since no wordpress is used in that page.
Contact html code
Likely an incorrect mime type in your .htaccess file. I suggest going into it and looking for any unwanted lines similar to the below and removing them.
AddHandler application/ etc.
and also ensure your type is set as follows:
AddType text/html .html
In order to open .htaccess in cPanel:
Click File Manager and make sure to tick Show Hidden Files (dotfiles) before clicking Go. Then the .htaccess should show up the location where wp (wp-admin, wp-content, wp-includes) is installed.
One possible cause is that there is a problem with your server configuration that is giving the visiting browser the wrong mime type.
The correct mime type for html is: text/html
The mime type that your server is sending is: application/x-httpd-php
You appear to be running Apache. As a result there are two possible files that could be causing this, either in .htaccess or in one of Apaches configuration files.
Try adding the text below to a .htaccess file in your directory, or look for a mention of application/x-httpd-php
AddType text/html .html
I had to add the following at it worked:
AddHandler application/x-httpd-php .php
I've had this issue a couple of times. The problem for me was the web server was automatically handling PHP requests outside of the .htaccess file. For some reason, changing settings in WordPress would sometimes cause a change in the .htaccess file, adding a handler for PHP. This would cause the server to burp at every PHP request thereafter and attempt to serve the file instead of handle it.
The solution, then, was to manually remove the handler that was automatically added to the .htaccess file (and leave a comment for myself so I wouldn't pull my hair out every time!)
Had same thing happen to me. I know this sounds funny but check to make sure none of the keys on your keyboard are stuck. i.e) ALT key , etc. if not. Try hooking up a new keyboard and then browse.

Inserting .txt file as html

Is there a way to insert a .txt file into a webpage and have the server/browser interpret it as html instead of just displaying the code?
I've tried using iframe as below, but that just displays the code instead of interpreting the code. I know the obvious way to do this would be to save the file as .htm and insert that file; the trouble is, my server doesn't let me upload .htm files.
<iframe src="url.txt" type="text" width="100%" style="height:1000px"></iframe>
No. In order to be interpreted by browser, it has to be sent with Content-Type: text/html HTTP herader (file extension is irrelevant by itself, but is often used by server to guess Content-Type). So if your server does not allow you to upload HTML files, you cannot do this.

HTML: force PDF download

I've a link to a PDF file in my page.
Safari opens the pdf file directly in the website. I would like to download it instead.
I've tried to add target="_blank" to <a> element, but it doesn't work if the pop-ups are disabled in the browser settings.
How can I solve this?
thanks
To make so, you need to change headers for .PDF files.
So, in your .htaccess, you need to do like this:
AddType application/octet-stream .pdf
You need to set the Content-Disposition HTTP header to attachment for this file.
Content-Disposition: attachment; filename=test.pdf
Depending on the web server you are using the way to configure this might vary. Another option is to have a server side script which would stream the pdf and set this header.
You'll need to dynamicaly force attachement headers using a server side script like PHP.
Here's an example using PHP :
<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');
?>
Edit :
$file = $_GET['file'];
readfile($file."pdf"); // Before doing this, check whather the user have permission to download that file.
call your script : download.php?file=document
will download document.pdf