Jump to content

Another extremely simple problem, this time its fopen()


Hangwire

Recommended Posts

Hi all.

What am I doing wrong here?

 

I cannot read from the file with fopen, this is the code.

 

<html>
<body>

<?php
$file=fopen("welcome.txt","r");
?>

</body>
</html> 

 

I get a blank page, although I have text written in that file. Whenever I set it to "w" it still shows nothing - when I check the file manually with notepad, I see that it's blanked - but I think thats meant to happen, after all "w" clears the file. Have I understood correctly?

 

This still shows a blank page, but it says it can't find the file if it's not in the directory - how it should be.

 

<html>
<body>

<?php
$file=fopen("welcome2123.txt","r") or exit("Unable to open file!");
?>

</body>
</html> 

 

tl;dr - Why doesn't fopen read anything from the txt file?

Encodings match - everything is in UTF-8, although I doubt thats the problem...

 

Help?  :-[

Link to comment
Share on other sites

I am by no means a expert but, fclose does what it says it closes the file so when you run other PHP or html code it wont try to do it inside fopen. that it my almost completely made up answer  ;)

 

The real definition:

The fclose() function causes the stream pointed to by stream to be flushed and the associated file to be closed.
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.