# Download a file with PHP (download.php?file=path_to_file)



## michaelsanford (Feb 25, 2003)

I've looked through the php.net help guides on fpasstrhru(); (http://www.php.net/manual/en/function.fpassthru.php)

Still for some reason I can't get the file that is being downloaded (either DOC or PDF or RTF for the most part) to take the name of the original file.

For some reason, it _always_ names the downloaded file download.php, but the content of the file is what I expect.

Is that because of my Apache configuration (I'm not allowing headers to be set properly by PHP)?


----------



## michaelsanford (Feb 25, 2003)

PS Since there is a possibility that I will need to parse PDF (binary) or RTF/DOC (text) how should I properly set the Content-Type header?

The file name still is not preserved when I use *header("Content-Disposition: attachment; filename=$fileName");*


----------



## macmasta (Mar 30, 2003)

just try integrating a forward which puts your browser to the file ...


----------



## dlloyd (Mar 30, 2003)

What browser are you using?
I remember having this problem with some versions of Safari.


----------



## michaelsanford (Mar 30, 2003)

I can't use a browser redirect, because it would totally defet using PHP in the first place (to hide the location of the file).

I've had this problem with all my browsers, interstingly (OmniWeb, IE)


----------



## dlloyd (Mar 30, 2003)

Hmmm, I don't know then. Sorry!


----------



## twister (Mar 30, 2003)

I've seen this a lot.  I'm not sure if it's an OS X issue or Safari or PHP.  

Maybe you could search for other free PHP download scripts then open them up and see if they have any code your missing.


----------



## michaelsanford (Mar 30, 2003)

I've had a look at a lot of examples on the PHP site, but I guess it's just one of those bugs that'll have to get worked out in time 

Thanks guys!


----------



## TommyWillB (Apr 13, 2003)

> _Originally posted by michaelsanford _
> *I've looked through the php.net help guides on fpasstrhru(); (http://www.php.net/manual/en/function.fpassthru.php)
> 
> Still for some reason I can't get the file that is being downloaded (either DOC or PDF or RTF for the most part) to take the name of the original file.
> ...


This is a browser thing... Sometimes you can trick it by submitting the form to your php page with a fake name following.

... Like this: download.php/my_file.pdf

BTW, even the vBulletin software that runs this forum has this problem when a post has an attachment in a format that can not be handled natively by the browers. (PNG images for example.)


----------

