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?  :-[

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.

Archived

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

×
×
  • 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.