Xianoth Posted August 28, 2007 Share Posted August 28, 2007 Ok, I am a noob, but thats why I am here.. So here's the problem I am having. I have a directory of .wav files set. What I want to do is take the .wav file from its location, pass it through lame to create a .mp3 of the file and then initiate a download of that file, the .mp3 does not have to or need to be saved on the server locally. The filename is being passed via the url as ?name=(filename), and I am using _GET to extract it. I have even gone so far as to set the variable: $name = _GET['name']; so that I can use $name in the php (see, i am paying attention.. ) The whole script i have so far is as follows: <?php $name = $_GET['name']; system('lame --quiet --nohist -b8 -mm ./$name -'); /> Which is working, but is giving me a direct output of the .mp3 file to my screen. I know I am missing a simple part of the function.. Thanks for all the help! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 28, 2007 Share Posted August 28, 2007 You need to set the headers to indicate an incoming file to the browser. I don't have a working example in front of me, but try going here: http://php.net/header Scroll down to where it says Example 1578. Download dialog. Remember to change the content-type and see if that doesn't give you a step in the right direction. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 I don't know what lame is but whenever you use PHP to generate an image file or a css you have to use header() to set the content type. Check out the comments on http://php.net/header to see some examples and people have talked about mp3 on there. Quote Link to comment Share on other sites More sharing options...
Xianoth Posted August 28, 2007 Author Share Posted August 28, 2007 You need to set the headers to indicate an incoming file to the browser. I don't have a working example in front of me, but try going here: http://php.net/header Scroll down to where it says Example 1578. Download dialog. Remember to change the content-type and see if that doesn't give you a step in the right direction. Bingo! I added the following: header ("content-type: audio/mpeg\n"); header (Content-Disposition: attachment; filename=\"$name.mp3\""); and it works.. Awesome! *rubs hands with glee* ahem.. :-D Thanks for the pointer! 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.