This is a discussion on LOCALHOST webserver not behaving same as remote server within the PHP Language forums, part of the PHP Programming Forums category; I'm developing a web site, which I test first on my PC (http://localhost/...) and then upload to the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm developing a web site, which I test first on my PC (http://localhost/...) and then upload to the web site on the internet when ok. I have a little bit of PHP code (in file download.php) which I use to force the Save dialogue when I want the user to download a PDF file. The hyperlink looks like:- http://localhost/download.php?filename=my_pdf_file.pdf This PHP works *fine* ... on the internet site - but *not* locally!!! On the localhost, instead of prompting to download the PDF file, it prompts to download the PHP file itself! What do I need to do / configure (and HOW and WHERE please) to get this to work locally?? My local web server is Apache 2, and I'm using PHP 4. The PHP code is just:- <?PHP header("Content-type: application/octet-stream"); header("Content-Length: ".filesize($filename)); header("Content-Disposition: attachment; filename=$filename"); $fp = fopen($filename, 'rb'); fpassthru($fp); fclose($fp); ?> Thanks! |
|
|||
|
(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500, eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk <bjrotm$mcc2a$1@ID-162217.news.uni-berlin.de>: > [...] > This PHP works *fine* ... on the internet site - but *not* locally!!! > > On the localhost, instead of prompting to download the PDF file, it > prompts to download the PHP file itself! > Is PHP enabled on your web server? Can you get a simple "hello world" PHP script executed? (Folloups set to comp.lang.php) |
|
|||
|
"Gary Petersen" <garyp1492@remove.meearthlink.invalid> wrote in message news:pan.2003.09.12.07.25.03.602372.1257@REMOVE.ME earthlink.INVALID... > (dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White > eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500, > eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk > <bjrotm$mcc2a$1@ID-162217.news.uni-berlin.de>: > > > > [...] > > This PHP works *fine* ... on the internet site - but *not* locally!!! > > > > On the localhost, instead of prompting to download the PDF file, it > > prompts to download the PHP file itself! > > > > Is PHP enabled on your web server? Can you get > a simple "hello world" PHP script executed? Yes - my simple test.php script to return current date in browser window works fine. |
|
|||
|
(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500, eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk <bjrotm$mcc2a$1@ID-162217.news.uni-berlin.de>: > I'm developing a web site, which I test first on my PC > (http://localhost/...) and then upload to the web site on the internet > when ok. > > I have a little bit of PHP code (in file download.php) which I use to > force the Save dialogue when I want the user to download a PDF file. > The hyperlink looks like:- > > http://localhost/download.php?filename=my_pdf_file.pdf > > This PHP works *fine* ... on the internet site - but *not* locally!!! > > On the localhost, instead of prompting to download the PDF file, it > prompts to download the PHP file > itself! > > What do I need to do / configure (and HOW and WHERE please) to get this > to work locally?? > > My local web server is Apache 2, and I'm using PHP 4. > > The PHP code is just:- > <?PHP > header("Content-type: application/octet-stream"); > header("Content-Length: ".filesize($filename)); > header("Content-Disposition: attachment; filename=$filename"); > $fp = fopen($filename, 'rb'); > fpassthru($fp); > fclose($fp); > ?> You don't need to close the file handle after using fpassthru() since it is already closed. In fact, attempting to close it causes an error which appends error message text to the end of your HTTP response. Nonetheless, your script should work, and it did on my system. I'm using Apache 1.3 and PHP 4.0.5. I used Lynx, Firebird and Amaya to download the file. Maybe it's a browser issue; read RFC 2616 section 19. My interpretation of that section is that the "filename=$filename" part provides only a suggested filename--not a required one. I believe that browsers are free to ignore it if they want to. |
|
|||
|
"Gary Petersen" <garyp1492@remove.meearthlink.invalid> wrote in message news:pan.2003.09.12.18.19.13.707599.297@REMOVE.MEe arthlink.INVALID... > (dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White > eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500, > eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk > <bjrotm$mcc2a$1@ID-162217.news.uni-berlin.de>: [...snipped...] > Maybe it's a browser issue; read RFC 2616 section 19. My interpretation > of that section is that the "filename=$filename" part provides > only a suggested filename--not a required one. I believe that > browsers are free to ignore it if they want to. I'm using the same browser on my PC. Some sessions to localhost and others to the internet site. |