473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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!


Jul 16 '05 #1
4 3945
(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk
<bj************@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)

Jul 16 '05 #2

"Gary Petersen" <ga*******@remove.meearthlink.invalid> wrote in message
news:pa*********************************@REMOVE.ME earthlink.INVALID...
(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk
<bj************@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.
Jul 16 '05 #3
(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk
<bj************@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.

Jul 16 '05 #4

"Gary Petersen" <ga*******@remove.meearthlink.invalid> wrote in message
news:pa********************************@REMOVE.MEe arthlink.INVALID...
(dolphin talk) eeeeeekkkkkk squueeeekkkkk Richard White
eeeeeiiiiiiikkkkkkkk squeeeeekk Fri, 12 Sep 2003 01:25:05 -0500,
eeeeeiiiiiiieeeeeekkkk eeeeekkkkkk eeiiikkkk
<bj************@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.

Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Will Stuyvesant | last post by:
Bruce Eckel has a good article about using a browser as UI for applications you write: http://mindview.net/WebLog/log-0045 His example code is nice, he sets up a webserver *and is able to kill...
2
by: Mark | last post by:
Hi, I'm fairly new to .NET and having problems getting an ASP.NET page working on my web host. The page works fine on my PC running against localhost. I have a MySQL database and a simple C#...
0
by: Alex Ayzin | last post by:
Hi, I need to use the remote IIS serverfor my development purposes. Do I need to have IIS server installed on my workstation, if I'm going to use the remote web server anyway? If I do, what kind...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
5
by: ljlevend2 | last post by:
Is there any way to create a local server during runtime? For example, if you add an existing Web Site to a Solution from within Visual Studio (by right clicking the solution in the Solution...
3
by: Shawn T | last post by:
I have an application with a page that has a web user control When I call that page that has this user control, locally (http:// localhost/ApplicationX/default.aspx) and also externally ie...
7
by: MrHelpMe | last post by:
Sorry everyone, NOTE: I have posted this question to another site but unfortunately, am not getting the answers I need only because those helping haven't worked with ASP. I am in desperate...
11
by: AAaron123 | last post by:
I have an vs2008 app that generates a website. I have a vs2008 app that uses the webbrowser and does this: WebBrowser1.Navigate(New Uri(address)) the address is: ...
5
by: Peter | last post by:
IIS6 on Windows Server 2003 I have a DotNetNuke website which works fine as long as I am openning the webpage on the web server, but when I try to open the same website from any client the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.