Jump to content

How do I create an url that downloads an mp3 file?


freaka

Recommended Posts

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.

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.