sntshkmr60 Posted May 17, 2012 Share Posted May 17, 2012 (edited) 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 May 17, 2012 by sntshkmr60 Link to comment Share on other sites More sharing options...
dsonesuk Posted May 17, 2012 Share Posted May 17, 2012 "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 More sharing options...
sntshkmr60 Posted May 17, 2012 Author Share Posted May 17, 2012 Why can't I read file.txt? Link to comment Share on other sites More sharing options...
dsonesuk Posted May 17, 2012 Share Posted May 17, 2012 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. Link to comment Share on other sites More sharing options...
HumbleApprentice Posted May 17, 2012 Share Posted May 17, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now