Jump to content


Photo

Php fopen() confusion


  • Please log in to reply
3 replies to this topic

#1 eatc7402

eatc7402
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 25 August 2006 - 03:08 PM

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/mai...ir/sp_main.htm", "r");
when local

$handle = fopen("http://www.mysite.or...g/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


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 August 2006 - 03:51 PM

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.

#3 eatc7402

eatc7402
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 25 August 2006 - 09:29 PM

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

#4 eatc7402

eatc7402
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 25 August 2006 - 10:34 PM

I solved my problem...

Use the    header() 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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users