Jump to content

Archived

This topic is now archived and is closed to further replies.

eatc7402

Php fopen() confusion

Recommended Posts

I am confused (although some feel this is a normal condition)
over the use of the fopen() function.

I am using Windows XP, and both IIS (locally), and Apache
(on the remote server). I am trying to get the equivelent of
an 'auto-link' (instead of the manual mouse click type) to
another .htm file in the 'main' directory.

In other words a link that goes to the selected .htm file
WITHOUT a mouse click, by using the fopen() function.
Am I all wet in trying to do it that way??

I am using PHP 4.3.10, and the user attribute in phi.ini
for allow_url_fopen is turned ON, indicated by phpinfo.

I have a small php script called by a form select button,
which in turn fopen's the desired file.

the php code (partial) looks likw this
$handle =  fopen("http://localhost/maindir/sp_main.htm", "r");
when local

$handle = fopen("http://www.mysite.org/sp_main.htm/", "r");
when remote

Also as a test I have included this code
echo "<a href=\"sp_main.htm\">sp_main_link</a>";
which works FINE, as I expected

But when executing the php fopen() code on the local OR remote
I get NO ERRORS  reported, but also NO link to the file
desired, just a blank screen.

I don't quite understand what is wrong. Any ideas??

eatc7402

Share this post


Link to post
Share on other sites
fopen wont display anything. It just opens the file ready for being edited or read by PHP.

To read the file you use fread, to edit the file your use fwrite.

if you want to display the contents of the file as part of the php gile use include or require.

Share this post


Link to post
Share on other sites
fopen() binds a named resource, specified by filename, to a stream. If filename is of the form "scheme://...", it is assumed to be a URL and PHP will search for a protocol handler (also known as a wrapper) for that scheme. If no wrappers for that protocol are registered, PHP will emit a notice to help you track potential problems in your script and then continue as though filename  specifies a regular file.
================================================
The php documentation (above) seems to indicate that if the file name contains an 'http:'
it will be treated 'special'. I assumed thats means to try to execute it it as an html
file in a cbrowser. True or false????

Maybe I am approaching this all wrong.

What I desire is to get an html link command '<a></a>' to execute AS IF WAS CLICKED
but actually not clicking. An 'automatic' linl call.

How can that be done??

eatc7402

Share this post


Link to post
Share on other sites
I solved my problem...

Use the    [color=red]header()[/color] commend instead of the fopen to get
an EXTERNAL HTML FILE to run.

Just be careful NOT to include ANY html form tags in the php script your running or you will
get CANNOT MODIFY THE HEADER errors.

eatc7402

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.