Mobile app version of vmapp.org
Login or Join
Connie744

: Change name of audio file for download I have some mp3 files which are named "my-audio.mp3" but now the client wants the visitor to be able to download and save these files to their desktop.

@Connie744

Posted in: #Apache #Filenames #Php

I have some mp3 files which are named "my-audio.mp3" but now the client wants the visitor to be able to download and save these files to their desktop. He doesn't like the name with the hyphen and wants them renamed to "MyAudio.mp3". Other than putting the renamed files into their own 'download' folder, how can I make this work on Apache?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Connie744

2 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

Apache can be configured to follow symbolic links. I tested creating a symbolic link for the desired name to the old name. On the command line I did:

ln -s My-Music.mp3 MyMusic.mp3


After which, Apache was happy to serve up the file at either localhost/My-Music.mp3 or localhost/MyMusic.mp3
To make it work you just have to have the correct option turned on in your .htaccess file:

Options +FollowSymLinks

10% popularity Vote Up Vote Down


 

@Speyer207

You can do this in PHP like so:

<?php
// We set the file type here
header('Content-Type: audio/mpeg');

// un-comment this line if you want to enforce download and comment the line above
// Content-Type "application/force-download"

// It will be called MyAudio.mp3
header('Content-Disposition: attachment; filename="MyAudio.mp3"');

// The MP3 Source
readfile('the-original-filename.mp3');
?>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme