Jump to content

How to create Download link with existing php


wcbennett3

Recommended Posts

I am managing a site that has .mp3 files (recordings of talks made in-house) available for streaming. I need to create a way for users to download .mp3s directly, but when they click the link, the audio automatically plays rather than downloads.

 

The link to the file is currently reading another php file, and is set up as follows:

 

<a href="<?php echo get_field('talk_info_talk_audio') ?>">Download the audio</a>

 

Any help is appreciated.

 

~wb

you need to make sure the php that is setting up the mp3 is also setting up the right headers, so that the browser knows what to do with the resource:

 

eg:

header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=something.mp3;");
header("Content-Length: ".filesize(<size of the file>));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.