Writing to a text file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have 2 servers; one running *nix w/ PHP4, and one running Windows 2k w/ 
PHP5; neither of which give me read permissions to write/create text files. 
Apparently, the *nix server has PHP in "Power Mode", but I'm still getting 
no love from fopen, and chmod via PHP doesn't work.

Any adivce?

Code skrait from the docs:

// Let's make sure the file exists and is writable first.
  if(is_writable($filename))
  {
   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'w'))
   {
    echo("Cannot open file ($filename)<br />");
    exit;
   }

   $somecontent = " ";
   // Write $somecontent to our opened file.
   if(fwrite($handle, $somecontent) === FALSE)
   {
    echo("Cannot write to file ($filename)<br />");
    exit;
   }

   echo("Success, wrote ($somecontent) to file ($filename)<br />");

   fclose($handle);
  }
  else
  {
   echo "The file $filename is not writable<br />";
   if (!chmod($filename, 0666))
   {
    echo "Cannot change the mode of file ($filename)<br />";
    exit;
   }
  } 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux