freaka Posted March 9, 2007 Share Posted March 9, 2007 ok, now i want to write a script that lets me create a url that downloads an mp3 file like this: http://djfreaka.com/songs.php?m=killerfx and have that goto this file http://djfreaka.com/music/killerfx.mp3 this is what I have so far, could someone help me with the missing part? <?php $m = $_GET['m']; $file = 'music/'.$m.'.mp3'; ?> effigy: Retitled the topic. Quote Link to comment https://forums.phpfreaks.com/topic/41987-how-do-i-create-an-url-that-downloads-an-mp3-file/ Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 You say another mod_rewrite, but this really is not considered a mod_rewrite. At any rate, I am really confused on what is being asked here. I guess this might be what you want: <?php $m=$_GET['m']; $file='http://djreaka.com/music/'.$m.'.mp3'; header("Location: " . $file); die(); ?> Your other option might include sending out a header that states it's an MP3 file and then print using fread. For more on the header data check out the first contribution located here http://us2.php.net/manual/en/function.fread.php --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/41987-how-do-i-create-an-url-that-downloads-an-mp3-file/#findComment-203579 Share on other sites More sharing options...
effigy Posted March 9, 2007 Share Posted March 9, 2007 See this example. Quote Link to comment https://forums.phpfreaks.com/topic/41987-how-do-i-create-an-url-that-downloads-an-mp3-file/#findComment-203582 Share on other sites More sharing options...
freaka Posted March 9, 2007 Author Share Posted March 9, 2007 hey thanks guys it works just fine now. i appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/41987-how-do-i-create-an-url-that-downloads-an-mp3-file/#findComment-203589 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 Try this also i use it. http://www.phpfreaks.com/forums/index.php/topic,95433.0.html Quote Link to comment https://forums.phpfreaks.com/topic/41987-how-do-i-create-an-url-that-downloads-an-mp3-file/#findComment-203591 Share on other sites More sharing options...
freaka Posted March 9, 2007 Author Share Posted March 9, 2007 hey that last one i like way better but i want to make it so it has two variables: cat & file. category being the directory (music, video, images) and file being the file name without it's extension. but what i would now like to do is get it where i can make a link like this: http://djfreaka.com/download.php?cat=music&file=killerfx and have it goto http://djfreaka.com/music/killerfx.mp3 see i want to get it to amend the filetype extension based on the category. like if the category is music the filetype would be .mp3 and if the filetype was images then it would be .jpg for reference i pasted the code below that you referred to. <?php // force to download a file // ex, ( [url=http://localhost/php/download.php?file=C:/Apache]http://localhost/php/download.php?file=C:/Apache[/url] Group/Apache2/hongkong.php ) // hope this can save your time :-) $file = $_REQUEST['file']; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); @readfile($file); Quote Link to comment https://forums.phpfreaks.com/topic/41987-how-do-i-create-an-url-that-downloads-an-mp3-file/#findComment-203698 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.