Jump to content

fopen problem


mmarkel

Recommended Posts

The following is one of my first scripts.  The html renders correctly, but the "C:\LogFile.txt" file is not being created and there are no error messages.

 

I presumed that this phrase in the code would provide an error message >> or die("can't open file"); but it did not.

 

Also, is there a good free debugger somewhere that allows one to step through the code one line at a time?

 

Please help.

/**************CODE LISTING ******************/

// this is on a windows machine

<html><body>

Got here

<php?

$myFile = "C:\\LogFile.txt";

$fh = fopen($myFile, 'a') or die("can't open file");

$stringData = "New Stuff 1\n";

fwrite($fh, $stringData);

$stringData = "New Stuff 2\n";

fwrite($fh, $stringData);

fclose($fh);

?>

<p> came here  </p>

</body></html>

Link to comment
https://forums.phpfreaks.com/topic/139313-fopen-problem/
Share on other sites

Make sure the file is CHMODed to have writing capabilities.

 

the file does not exist.  according to what I read the 'a' option (append) in the following line in my code

$fh = fopen($myFile, 'a') or die("can't open file");

 

..would create the file if it does not exist. 

Also, this is a windows machine. chmod is *nix command.  I am the administrator on the machine and have "root"-like privileges, so file creation permissions is not the issue.

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728656
Share on other sites

How are you invoking the script? It needs to be processed via your webserver, so it has to be invoked via http://localhost/yourscript.php

 

Ken

 

I am invoking it as you suggest, and the html is rendering fine.  Also, I have other scripts that I did not author that are running the server side Php correctly.

Link to comment
https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728657
Share on other sites

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.