LOCALHOST webserver not behaving same as remote server

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2003
Richard White
 
Posts: n/a
Default LOCALHOST webserver not behaving same as remote server


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!




Reply With Quote
  #2 (permalink)  
Old 09-12-2003
Gary Petersen
 
Posts: n/a
Default Re: LOCALHOST webserver not behaving same as remote server

(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)

Reply With Quote
  #3 (permalink)  
Old 09-12-2003
Richard White
 
Posts: n/a
Default Re: LOCALHOST webserver not behaving same as remote server


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


Reply With Quote
  #4 (permalink)  
Old 09-12-2003
Gary Petersen
 
Posts: n/a
Default Re: LOCALHOST webserver not behaving same as remote server

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

Reply With Quote
  #5 (permalink)  
Old 09-13-2003
Richard White
 
Posts: n/a
Default Re: LOCALHOST webserver not behaving same as remote server


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



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:54 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0