My issue was that I didn't understand that the PHP code snippet is for server-side execution. I was trying to use it while hosting content on my Apple MobileMe iDisk.
Thanks everyone for your help!
Printable View
Please, do not create a public file proxy on your server, as suggested by "Eye for Video" and "scragar", this is a MEGA HUGE security hole :eek:, an EXTREMELY DANGEROUS feature :eek:! Anyone could use it to download anything from the server, including password files, personal cookies, credit card information, stealing identity and even locally crack all username / passwords to remotely access your server and use it for whatever they want... NEVER CREATE A PUBLIC FILE PROXY :mad:!!! Geez...
Just a quick thought: any zip file is downloadable. Just place your mp3 in it.
Jack O'Connell
Thank you, all who contributed to this. You've just made things a lot easier for me. Some of my clients didn't know how to right-click a file and what to choose to save the file to their computer. Even with the instructions right there on the page, it was too difficult. Now when they click on a link, their browser asks whether they want to run or save the file. Excellent!
I did make one modification: I put direct_download.php in a dedicated folder and link to it that way: <a href="\[my catch-all folder]\direct_download.php?file=..."> That way, I don't have to remember to copy the php file to every folder in which I'm storing files for download, and I can still use it on any page on the site.
I need to make my site more accessible, especially to mobile users, and more standards-compliant, so I'll be studying here when I have the time.
-- Timothy J. McGowan
<?php
//Force file download instead of streaming
//Coded by Code018
$file=$_GET['file'];
$file=str_replace(" ","%20",$file);
header('Content-type: application/octet-stream');
// It will be called the base file name
$url = $file;
$file_name = basename($url);
//lets be nice to the user and replace the spaces with happy things
//$file_name=str_replace("%20","_",$file_name);
//this is the filename we get to play with
$infile = $url;
$file_name = stristr ($infile,basename ($infile));
header('Content-Disposition: attachment; filename="'.urldecode($song_name.mp3.'"');
// The File source is in .mp3 originally
//This is the file that we are downloading
readfile(stripslashes($file));
?>
pls reply fastQuote:
when add .mp3 file download but not actual
Here's how you make download link for MP3 files.
change "octet/stream" to "audio/mp3"