You are here: Writing to a text file « PHP « IT news, forums, messages
Writing to a text file

Posted by "JesterXL" on 10/20/27 11:25

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;
}
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация