1

I have a windows server 2008 standard edition. I'm trying to execute this simple command so I can later write admin logs on files. Info ain't writing on files or creating the file if it doesn't exist. And the page isn't issuing and warnings or errors about windows permission.

<?php 
$file=fopen("1.txt","a");
fwrite($file,"Hello");
?>

Any help ?

  • What are the permissions on the file? – Explosion Pills Apr 30 '11 at 12:55
  • check if there are any errors or E_WARNINGS generated. according to manual If the open fails, an error of level E_WARNING is generated. You may use @ to suppress this warning. – Khurram Ijaz Apr 30 '11 at 12:59
  • please put at the top of your php file `error_reporting(-1); ini_set( 'display_errors' , 1 );` and paste the message here .. if it is still unclear. – tereško Apr 30 '11 at 13:01

1 Answers1

0

Try this to find out if there is an error opening the file without relying on PHP's error reporting:

$file = fopen("1.txt","a") or die("Error opening file: " . print_r(error_get_last()));

Secondly, if you're not getting any errors on the command line, make sure your PHP is set up to display them all. Check out this question for some helpful tips on that.

Community
  • 1
  • 1
Thilo
  • 17,565
  • 5
  • 68
  • 84
  • "Array ( [type] => 2 [message] => fopen(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '1.0/no DST' instead [file] => C:\inetpub\wwwroot\10.php [line] => 2 ) Error opening file: 1" – ProgrammingEnthusiast Apr 30 '11 at 13:11
  • A simple google search might help with that? http://www.google.com/search?q=%22It+is+not+safe+to+rely+on+the+system%27s+timezone+settings%22 – Thilo Apr 30 '11 at 13:19
  • Edited the timezone but still not working. + it's giving this error also "Warning: fopen(2.txt): failed to open stream: Permission denied in C:\inetpub\wwwroot\10.php on line 3" – ProgrammingEnthusiast Apr 30 '11 at 13:42
  • Well there's your problem then. I'm no expert on Windows file system permissions, but make sure that the user executing the script can write to the directory in question, and to the file if it already exists. – Thilo Apr 30 '11 at 13:45