Jump to content
sntshkmr60

Can't read the file

Recommended Posts

I am developing the file locally with LAMPP and my source file is like this:

<?php echo "The server is working"; ?><?php$file=fopen("file.txt", "r") or exit("Unable to open file!");?>

In the same directory is a text file named file.txt and it has a line on text in it. The output however is only The server is working. Nothing else.

Edited by sntshkmr60

Share this post


Link to post
Share on other sites

"The server is working" will show if the server is working or not!$file=fopen("file.txt", "r") or exit("Unable to open file!");IS ONLY for the searching of and IF found opening, ELSE show error message, you now have show the contents of the file.http://w3schools.com/php/php_file.asp

Share this post


Link to post
Share on other sites

Like i said! you don't have the code to read/display the content of file, OPEN yes! read or display NO! thats why i supplied a link to show you how.

Share this post


Link to post
Share on other sites

You can't read the file because you only call the function fopen. You did not create an argument telling the function what to do, so it is just standing there waiting for you to give it some instruction. The instruction is an argument. To tell it to get your line of code, the syntax is as follows: echo fgets ($file); //this gets whatever is in your filefclose($file); //This function close your file. You should always close your file after you open it.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...