LOCALHOST webserver not behaving same as remote server

R

Richard White

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!
 
G

Gary Petersen

(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk
[...]
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)
 
G

Gary Petersen

(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top