Quantcast
Channel: Young Digital Group » wordpress
Viewing all articles
Browse latest Browse all 4

Video Tutorial: How To Force Download an MP3 File Instead of Streaming

$
0
0

Show me the video

A word of warning for the reader, this post will get very techie, I wanted to force download an MP3 file, instead of streaming, the solution requires good knowledge of WordPress, Servers and computer coding. I do explain every step as clearly as possible, but it may still be too much for the average person.

To clearly demonstrate the problem, here are two image links. The one on the left (#1) uses the standard add link process, the one on the right (#2) uses custom code to force the download of the MP3. The preference is to download the file, not play in the browser. Click on both to see what I mean.

1. downloadmp3      2. downloadmp3

Thanks to Eye For Video from Webdeveloper.com for providing the solution (used in the image to the above right).

A video walking through the process is below.

Here is the code to be used

<?php
$file = $_GET['file'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header ("Content-Length: ".filesize($file));
readfile($file);
exit;
?>

Save this code in a file called direct_download.php and save it in the same folder as the MP3 file on your server.


Trying to manage too many passwords? You need LastPass.


Use the following code on your website to call up this file

<a href="direct_download.php?file=filename.mp3">Download the mp3</a>

As I wanted to use an image instead of a text link, I used the following code

<a href="../wp-content/uploads/Podcasts/direct_download.php?file=3RPPTue28May2013YoungDigitalGroup.mp3">
<img alt="downloadmp3" src="http://youngdigitalgroup.com.au/wp-content/uploads/2013/05/downloadmp3.png" 
width="158" height="35" /></a>

This video is the process explaining how I created and saved these files to make it all work

 

 

The post Video Tutorial: How To Force Download an MP3 File Instead of Streaming appeared first on Young Digital Group.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images