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

Link to comment
Share on other sites

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>));
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.