How to implement Content-Disposition: an attachment?

I'm trying to make mp3 on my site load with a left click, instead of right clicking and save as. Therefore, to do this, I have to set the Content-Disposition: attachment. This is my first website, so I'm new to how to actually do this, but can I do this in my html markup or install it somehow from my hosting site?

Here is an example of what my markup looks like.

<div class="download"> <a href="MP3/Morgan Page, Sultan & Ned Shepard, and BT feat. Angela McCluskey.mp3" <img src="img/dlicon.png"/></a> </div> 
+13
html php content-disposition
Jan 16 '12 at 5:00
source share
3 answers

Example MP3 lists:

 <a href="download.php?file=testing.mp3">Download MP3</a> <a href="download.php?file=testing2.mp3">Download MP3</a> 

download.php:

 <?php $file = $_GET['file']; header('Content-type: audio/mpeg'); header('Content-Disposition: attachment; filename="'.$file.'"'); ?> 
+17
Jan 16 2018-12-12T00:
source share

As others have said, you do not do this in HTML, and a dynamic solution (e.g. using PHP) is redundant.

In your case, I configured the Content-Disposition header in the web server configuration. For Apache, you can set a header based on location or create a .htaccess file that matches specific file names.

+3
Mar 27 '14 at 12:54 on
source share

PHP has a special function:

bool http_send_content_disposition ( string $filename [, bool $inline = false ] )

See the PHP manual here: http://de2.php.net/manual/en/function.http-send-content-disposition.php

+1
Jul 12 '14 at 9:28
source share



All Articles