QUOTE(herb2006 @ Nov 8 2009, 06:01 AM)

I am sorry for that.
your script have no mistakes, the cause is permission limit.
the cause of the warnings , Warning fopen('msg/nik.dat','w') failed to open stream, is fopen have no perms to 'w' file.
so we must
set perms to the folder msg first, should set 0777.
then set perms to the file nik.dat, should set 0666.
then the function fopen will work!
file permissions should be changed under FTP, such as FlashFXP, not through php script,
but via the file manager of Zymic, you can also finish such work.
(0777 = rwxrwxrwx ; 0666 = rw-rw-rw-)
Thank you very mach.
I set perms to the folder in File Manager.All right if a new file.
If already a file exists then need unlink before fopen.chmod - error.
I'm from Ukraine.1 time PHP.I design Clarion.
CODE
function saveFile($f,$contents,$mode="w"){
if(file_exists($f)==true)unlink($f);
$fo=fopen($f, $mode);
flock ($fo,LOCK_EX);
ftruncate ($fo,0);
$result=fwrite($fo,$contents);
fflush ($fo);
flock ($fo,LOCK_UN);
fclose($fo);
return $result;
}