mmarkel Posted January 3, 2009 Share Posted January 3, 2009 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 More sharing options...
Michdd Posted January 3, 2009 Share Posted January 3, 2009 Make sure the file is CHMODed to have writing capabilities. Link to comment https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728650 Share on other sites More sharing options...
kenrbnsn Posted January 3, 2009 Share Posted January 3, 2009 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 Link to comment https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728653 Share on other sites More sharing options...
mmarkel Posted January 3, 2009 Author Share Posted January 3, 2009 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 More sharing options...
mmarkel Posted January 3, 2009 Author Share Posted January 3, 2009 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 More sharing options...
mmarkel Posted January 3, 2009 Author Share Posted January 3, 2009 i created the file manually..LogFile.txt, and ran the script and it still does not append and there is no error message. Also, not sure if this helps or not, but I am running a xampp implementation.... Link to comment https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728659 Share on other sites More sharing options...
kenrbnsn Posted January 3, 2009 Share Posted January 3, 2009 The opening tag for PHP is "<?php" not "<php?" as it is written, HTML is eating everything between the "<php?" and the "?>". Ken Link to comment https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728661 Share on other sites More sharing options...
cytech Posted January 3, 2009 Share Posted January 3, 2009 Your file is trying to save directly to the C drive, is your C drive setup as the root of your server? Try removing the C:\\ and just creating the file itself and see where it creates it. I'm thinking you don't have permissions to write a file to C. Link to comment https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728662 Share on other sites More sharing options...
mmarkel Posted January 3, 2009 Author Share Posted January 3, 2009 The opening tag for PHP is "<?php" not "<php?" as it is written, HTML is eating everything between the "<php?" and the "?>". Ken that was so stupid of me.....thanks. I changed the tag and it worked as designed Link to comment https://forums.phpfreaks.com/topic/139313-fopen-problem/#findComment-728665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.