Jump to content

Can't read the file


sntshkmr60
 Share

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
Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...