kwdrysdale Posted January 1, 2009 Share Posted January 1, 2009 I am using a web-based media player to play my podcast.xml file. Everything works great except for one tiny issue. There is a clickable link that is supposed to allow the user to download the audio file to their computer. Well...when the user clicks the link it opens a new window and then plays the audio file with whatever program the person has setup to play mp3 files. My goal is to use a force download script to bypass the users mp3 player of choice and save the file to their computer. If I try my PHP script directly on a webpage everything works fine. The problem is when I try to take that exact same link and use it in my podcast.xml file. If anyone is able to help with a solution it would be greatly appreciated. I will post the code I am using for the force_download.php as well as the podcast.xml: force_download.php: <?php // get the file url from querystring $filename = realpath($_GET['file']); // Error: only files that are in a subdir of this script can be downloaded $current_dir = dirname(realpath($_SERVER['SCRIPT_FILENAME'])); if($current_dir != substr(dirname($filename), 0, strlen($current_dir))) { die( "The requested file cannot be retrieved for security 1 reasons."); } // Error: PHP files cannot be downloaded if(strToLower(substr($filename,strlen($filename)-3, 3) == 'php')) { die( "The requested file cannot be retrieved for security reasons."); } // Error: file is not found if(!file_exists($filename)) { die("The requested file could not be found"); } // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } // build file headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // header for the content type $ext = strToLower(substr($filename,strlen($filename)-3, 3)); if ($ext == "mp3" ) { header("Content-Type: audio/x-mp3"); } else if ($ext == "jpg") { header("Content-Type: image/jpeg"); } else if ($ext == "gif") { header("Content-Type: image/gif"); } else if ($ext == "png") { header("Content-Type: image/png"); } else if ($ext == "swf") { header("Content-Type: application/x-shockwave-flash"); } else if ($ext == "flv") { header("Content-Type: video/flv"); } // and some more headers header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); // refer to file and exit readfile("$filename"); exit(); ?> podcast.xml <?xml version="1.0" encoding="UTF-8"?> <rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> <channel> <title>Solid Rock Ministries Podcast</title> <description>The best way to stay up to date with all the current messages from SRM!</description> <link>http://www.solidrockministries-mb.ca</link> <language>en-us</language> <copyright>Copyright 2008</copyright> <lastBuildDate>Thur, 1 Jan 2009 13:37</lastBuildDate> <pubDate>Wed, 31 Dec 2008 16:22</pubDate> <docs></docs> <webMaster>kmdrysdale@shaw.ca</webMaster> <item> <title>Wed Dec 31/08 - New Year's Eve</title> <link>force_download.php?file=mp3/125-Wed Dec 31, 2008-New Year's Eve.mp3</link> <description>9 - Give an offering of worship to the Lord as we declare the new season.</description> <enclosure url="http://www.solidrockministries-mb.ca/mp3/125-Wed%20Dec%2031,%202008-New%20Year's%20Eve.mp3" length="57972888" type="audio/mpeg"/> <itunes:duration>2:41:02</itunes:duration> <category>Podcasts</category> <pubDate>Wed, 31 Dec 2008 19:30</pubDate> </item> <item> <title>Sun Dec 28/08 - Live in God's Season</title> <link>http://www.solidrockministries-mb.ca/mp3/124-Sun%20Dec%2028,%202008-Live%20in%20God's%20Season.mp3</link> <description>Pastor Dave shares more about our new season that we are in. Prepare yourself to live in God's season!</description> <enclosure url="http://www.solidrockministries-mb.ca/mp3/124-Sun%20Dec%2028,%202008-Live%20in%20God's%20Season.mp3" length="476705524" type="audio/mpeg"/> <itunes:duration>2:12:25</itunes:duration> <category>Podcasts</category> <pubDate>Sun, 28 Dec 2008 10:00</pubDate> </item> <item> <title>Sun Dec 21/08 - The New Season</title> <link>http://www.solidrockministries-mb.ca/mp3/123-Sun%20Dec 21,%202008-The%2New%20Season.mp3</link> <description>Pastor Dave shares more detail about the new season we are in and releases an opportunity to give on New Years Eve.</description> <enclosure url="http://www.solidrockministries-mb.ca/mp3/123-Sun%20Dec 21,%202008-The%2New%20Season.mp3" length="39222800" type="audio/mpeg"/> <itunes:duration>2:15:16</itunes:duration> <category>Podcasts</category> <pubDate>Sun, 21 Dec 2008 10:00</pubDate> </item> <item> <title>Wed Dec 17/08 - Ministry Gifts are Personal</title> <link>http://www.solidrockministries-mb.ca/mp3/122-Wed%20Dec%2017,%202008-Elder%20Al%20Drysdale-Ministry%20Gifts%20are%20Personal.mp3</link> <description>Elder Al Drysdale teaches us that God gave us each, individually, the ministry gifts that are placed over us.</description> <enclosure url="http://www.solidrockministries-mb.ca/mp3/122-Wed%20Dec%2017,%202008-Elder%20Al%20Drysdale-Ministry%20Gifts%20are%20Personal.mp3" length="24927480" type="audio/mpeg"/> <itunes:duration>1:30:16</itunes:duration> <category>Podcasts</category> <pubDate>Wed, 17 Dec 2008 19:30</pubDate> </item> </channel> </rss> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 So you're trying to use the force_download.php link in the <enclosure> tab in podcast.xml? Quote Link to comment Share on other sites More sharing options...
kwdrysdale Posted January 2, 2009 Author Share Posted January 2, 2009 not the <enclosure> tag, inside the <link> tags. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 Umm, what does it do if you use the force_download.php link rather than a direct link to the MP3? Quote Link to comment Share on other sites More sharing options...
kwdrysdale Posted January 2, 2009 Author Share Posted January 2, 2009 A direct link to the MP3 will open a new window and (for me) play the file in QuickTime. Others it may play in WindowsMedia, RealPlayer, etc. If I use force_download.php it will bring up the save dialog and download direct to the users computer rather than stream the media. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 I mean, what happens when you use it in podcast.xml and try to load it in the media player that reads the podcast.xml file? Does it not play? Quote Link to comment Share on other sites More sharing options...
kwdrysdale Posted January 2, 2009 Author Share Posted January 2, 2009 Sorry folks. I just figured out my problem. I was trying my link on an old file (so none of our members would have any problems) that did not have any apostrophe ( ' ) characters. Then when trying it on a newer file, that had an apostrophe, it would not work proper. I'll just have to remember not to use any special characters in my filenames. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.