Jump to content

Php fopen() confusion


eatc7402

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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.