Jump to content

cannot open file


jimfog

Recommended Posts

Ι am trying to open a file using the fopen function, the code is the following:

<?phpfopen("c:\\xampp\\htdocs\\hijohn.txt","r")?>

I have setup a XAMPP server in my system for testing.I am relative new to PHP and i cannot understand what am i doing wrong.the file containinig the code is also named hijohn.That is the browser URL i type to access the file:http://localhost/hijohn.php Any help is appreciated since i am trying to grasp this powerful language.Thanks.

Link to comment
Share on other sites

With a semi-colon at the end, that should return a resource that you can use with fread. fopen does not return any real data. If you were hoping that fopen would output the data to a browser, uh-uh. You could do that like this:$data = file_get_contents("c:\\xampp\\htdocs\\hijohn.txt");echo $data;What exactly are you trying to do?

Link to comment
Share on other sites

  • 2 weeks later...
With a semi-colon at the end, that should return a resource that you can use with fread. fopen does not return any real data. If you were hoping that fopen would output the data to a browser, uh-uh. You could do that like this:$data = file_get_contents("c:\\xampp\\htdocs\\hijohn.txt");echo $data;What exactly are you trying to do?
I am not trying to do anything particular.I am just start learning PHP.So, and in relation to what you said, whatever the php command, nothing will be output to the browser unless i use the echo statement.Correct?Am i saying it correctly?
Link to comment
Share on other sites

There are several ways to output data to the browser. fopen is not one of them. echo is the most common way to output a string (which can contain HTML or any other kind of data). readfile is specifically designed to output file contents directly. See if the example looks like something you'd want.

Link to comment
Share on other sites

There are several ways to output data to the browser. fopen is not one of them. echo is the most common way to output a string (which can contain HTML or any other kind of data). readfile is specifically designed to output file contents directly. See if the example looks like something you'd want.
I used the file get contents function(as you did) to do my job.And it worked.D..... it's amazing what computers can do, so few lines of code, yet, so much power.Thanks.
Link to comment
Share on other sites

The old fopen, fread, fclose functions are analogous to traditional Unix system functions, so you see them used a lot in legacy code (not to mention C applications). They're a little closer to the metal, as they say, but needlessly so in a scripting environment. The newer functions allocate memory and buffers more efficiently, too.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...