Jump to content

[SOLVED] Process a file and then download.


Xianoth

Recommended Posts

Ok, I am a noob, but thats why I am here..  ;D

 

 

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

 

 

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!

Link to comment
https://forums.phpfreaks.com/topic/67058-solved-process-a-file-and-then-download/
Share on other sites

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.

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.

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!

 

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.