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
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.

Link to comment
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.

 

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!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.