amites Posted December 27, 2008 Share Posted December 27, 2008 Hello, This one is stumping my blain, hoping I can draw upon some help here, I am building an application that will allow users to preview an mp3 file in a flash player, question is, can this be done without using header(location: URL) I'd like to hide the mp3's outside of the public_html folder, don't have to but I would like to any ideas? I'm building this using the Code Igniter framework if that makes a difference to anyone's thought process Quote Link to comment https://forums.phpfreaks.com/topic/138556-hide-an-mp3-file-with-php/ Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 The flash application should not care where the MP3 file is located. I am not sure how that software works etc, but yea should be possible. However if you want them to be able to download it you may want to store the mp3s with a randomly generated hash for the file name, then use the DB to have them download with the original name etc. At least that is my 2 cents. But yea the flash player should not care where the MP3 is as long as you give it the correct path. Quote Link to comment https://forums.phpfreaks.com/topic/138556-hide-an-mp3-file-with-php/#findComment-724452 Share on other sites More sharing options...
Philip Posted December 27, 2008 Share Posted December 27, 2008 As seen in the header page in the PHP manual: <?php $filename = "theDownloadedFileIsCalledThis.mp3"; $myFile = "/absolute/path/to/my/file.mp3"; $mm_type="application/octet-stream"; header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); // makes it no-cache basically header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($myFile)) ); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Transfer-Encoding: binary\n"); readfile($myFile); ?> I haven't tested it 100%, but I'm pretty sure it works. Basically it just takes the mp3, and echos the contents to this page - which since you sent the headers saying it's a mp3 and not a page.... it'll play the song. Quote Link to comment https://forums.phpfreaks.com/topic/138556-hide-an-mp3-file-with-php/#findComment-724505 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.