473,473 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fopen problems

I'm trying to fopen a file this way:

$handle = fopen("http://localhost/test.html", "r");

but tha page remains "loading .." for 30 seconds and then goes in
timeout.

However I can open that file this way:

$handle = fopen("c:\web\test.html", "r");

What is the difference and how can I make the first instruction to
work?

Best regards.

F.
Jun 2 '08 #1
15 2360
On 23 May, 11:35, joker197cinque <joker197cin...@gmail.comwrote:
I'm trying to fopen a file this way:

$handle = fopen("http://localhost/test.html", "r");

but tha page remains "loading .." for 30 seconds and then goes in
timeout.

However I can open that file this way:

$handle = fopen("c:\web\test.html", "r");

What is the difference and how can I make the first instruction to
work?

Best regards.

F.
What happens if you just put http://localhost/test.html in your
browser address bar?
Does the page display?
Jun 2 '08 #2
On 23 May, 11:35, joker197cinque <joker197cin...@gmail.comwrote:
I'm trying to fopen a file this way:

$handle = fopen("http://localhost/test.html", "r");

but tha page remains "loading .." for 30 seconds and then goes in
timeout.

However I can open that file this way:

$handle = fopen("c:\web\test.html", "r");

What is the difference and how can I make the first instruction to
work?

Best regards.

F.
Also have you read the manual on fopen?
http://uk.php.net/fopen
where it says:
If PHP has decided that filename specifies a registered protocol, and
that protocol is registered as a network URL, PHP will check to make
sure that allow_url_fopen is enabled. If it is switched off, PHP will
emit a warning and the fopen call will fail.

Have you got warning messages enabled?
Jun 2 '08 #3
joker197cinque escribió:
$handle = fopen("http://localhost/test.html", "r");

but tha page remains "loading .." for 30 seconds and then goes in
timeout.

However I can open that file this way:

$handle = fopen("c:\web\test.html", "r");

What is the difference and how can I make the first instruction to
work?
http://localhost/test.html is a web site and c:\web\test.html is a file
in your hard disc.

Do you really need to load a file from a third-party web server? I'm
almost sure that a simple fopen('test.html', 'r') will do for you.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 2 '08 #4
On 23 Mag, 12:55, Captain Paralytic <paul_laut...@yahoo.comwrote:
Have you got warning messages enabled?
If I browse that URL via browser it works.

If I add error_reporting ALL I obtain:

[function.fopen]: failed to open stream: A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has
failed to respond. in C:\AppServ\www\go.php on line 4

Fatal error: Maximum execution time of 30 seconds exceeded in C:
\AppServ\www\go.php on line 4

Any help appreciated.
Jun 2 '08 #5
On 23 Mag, 13:06, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
Do you really need to load a file from a third-party web server? I'm
almost sure that a simple fopen('test.html', 'r') will do for you.
I tried with relative path too...with no luck
Jun 2 '08 #6
joker197cinque escribió:
On 23 Mag, 13:06, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
>Do you really need to load a file from a third-party web server? I'm
almost sure that a simple fopen('test.html', 'r') will do for you.

I tried with relative path too...with no luck
Do you have a specific need? Coding randomly will eventually produce
something that runs without errors or timeouts but... will it solve your
problem?
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 2 '08 #7
On 23 May, 12:06, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
Do you really need to load a file from a third-party web server? I'm
almost sure that a simple fopen('test.html', 'r') will do for you.
He already said in the OP:
However I can open that file this way:

$handle = fopen("c:\web\test.html", "r");
Jun 2 '08 #8
On 23 Mag, 13:48, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
joker197cinque escribió:
On 23 Mag, 13:06, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
Do you really need to load a file from a third-party web server? I'm
almost sure that a simple fopen('test.html', 'r') will do for you.
I tried with relative path too...with no luck

Do you have a specific need?
I would only open a local url from a php page.
Coding randomly will eventually produce
something that runs without errors or timeouts but... will it solve your
problem?
I didn't understand.
Jun 2 '08 #9
If I open url this way:

fopen("test.html", "r") from my go.php page it works.

I now have to pass some vars to this page:

fopen("test.html?var1=test&var2=test", "r");

but this does not work.

Which is the correct way?

Best regards.
Jun 2 '08 #10
joker197cinque escribió:
If I open url this way:

fopen("test.html", "r") from my go.php page it works.

I now have to pass some vars to this page:

fopen("test.html?var1=test&var2=test", "r");

but this does not work.

Which is the correct way?
You mean this?

::: go.php

<?php
$var1 = 'test';
$var2 = 'test';
require('test.html');
?>

::: test.html

<?php
print "Hello $var1 and $var2\n";
?>

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 2 '08 #11
On 23 Mag, 14:27, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
You mean this?
[CUT]

No, I mean to fopen (or whatelse function) a simple URL that should
contain some stuff in querystring (search.php?q=stuff) as when I try
to do this:

fopen("test.html?var1=test&var2=test", "r");

it does not work.

Any help?

Regards.
Jun 2 '08 #12
joker197cinque wrote:
On 23 Mag, 14:27, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
>You mean this?

[CUT]

No, I mean to fopen (or whatelse function) a simple URL that should
contain some stuff in querystring (search.php?q=stuff) as when I try
to do this:

fopen("test.html?var1=test&var2=test", "r");

it does not work.

Any help?

Regards.
What do **YOU** mean by open? You seem to be flipping between two
things. On the one hand you seem to want to open something (a file) so
that can read in its contents and do something with it. On the other
hand, you seem to simply want to "open" a web page, aka displaying it,
with passed in parameters. Can you explain exactly what you are trying
to do? That is, what is your larger problem?
Jun 2 '08 #13
..oO(joker197cinque)
>On 23 Mag, 14:27, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
>You mean this?

[CUT]

No, I mean to fopen (or whatelse function) a simple URL that should
contain some stuff in querystring (search.php?q=stuff) as when I try
to do this:
Yes, but if the requested file is on the same machine, you can use other
ways to include it and pass values to it, as shown in Álvaro's example.
Might require some changes in the code, though.
>fopen("test.html?var1=test&var2=test", "r");

it does not work.

Any help?
Just to summarize:

* opening test.html directly on disk with fopen()
-works

* calling http://localhost/test.html?var1=test&var2=test in the browser
-works

* opening http://localhost/test.html?var1=test&var2=test with fopen()
-fails

Correct?

Can you open other external URLs with fopen() or file_get_contents()?
Does something appear in the server's logfiles? Does this all happen on
a single machine or is the web server running on another machine than
the browser for example?

Micha
Jun 2 '08 #14
..oO(sheldonlg)
>What do **YOU** mean by open? You seem to be flipping between two
things. On the one hand you seem to want to open something (a file) so
that can read in its contents and do something with it. On the other
hand, you seem to simply want to "open" a web page, aka displaying it,
Opening a web page with fopen() doesn't necessarily mean that it's
intended for displaying it. You pass some variables to an external
script via HTTP, get the results back and then do something with it.
But for the OP this call fails for some unknown reason.

Micha
Jun 2 '08 #15
joker197cinque a écrit :
fopen("test.html?var1=test&var2=test", "r");

it does not work.
As far as I know, if you don't specify a protocol, it tries to open as
file, and the filesystem has absolutely no idea how to handle ? and &,
it just treats them as part of the file name.

So I think you're just trying to open the file
"test.html?var1=test&var2=test" in the current directory, which file of
course doesn't exist, so it fails.

Stick to loading
"http://whateverdomain.tld/test.html?var1=test&var2=test" and find your
issue, cause this is the way it should work if you need an URI parsing.

My guess is your problem is some kind of configuration problem, either
with your local webserver, or php file handling, or url handling (do PHP
know what "localhost" is ?) that prevent the access.

Regards,
--
Guillaume
Jun 2 '08 #16

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

Similar topics

3
by: flupke | last post by:
Hi, i have a piece of code that reads a csv list. For instance: 1,index.html 2,linux.html I read these in an array and then i want to use the filename (2nd array element) to make a file and...
2
by: Mister Zimbu | last post by:
I'm having problems with a program I wrote- when it comes time to output a file, the call to fopen locks up and I have to break the program manually. I've pinpointed the actual stopping point to...
7
by: git_cs | last post by:
Hey, guys and gals Somedays ago, I had asked for the DES algorithm in C language. Although I have written the algorthim in C myself, I am facing a peculiar problem, which I hope some of u guys and...
4
by: lucyachammond | last post by:
I have a 3rd party real-estate website written in php. I would like to call an asp script on a separate webserver each time a new real-estate item is added to the database on the php site. The...
3
by: nihad.nasim | last post by:
Hi, I am kind of new to PHP and while learning I came across the touch command which creates a new file. I also came up with fopen to open a file. In both cases I am having the same problem: ...
16
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
1
by: carpediem | last post by:
Hi, I am developing an application in Borland C++ 6, one of my functions opens a file and loads it into the memory. I have never had problems with fopen, but this bug is really weird, fopen...
3
by: IamtheEvster | last post by:
Hi there, I'm using fopen for the first time and I know I'm running into a permissions problem, but I can't seem to resolve it and any help would be greatly appreciated. I'm running PHP5 and...
0
by: botho.willer | last post by:
Hello! Some time ago I discovered a script on php.net that uses a fopen handle on a .htaccess-protected directory to check the authorization of a user. The crucial Code is this: $handle =...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.