Help - Search - Members - Calendar
Full Version: Function Fopen
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
ugser
Text file is 'msg/nik.dat'.
Function file_exists('msg/nik.dat') return true.
Warning fopen('msg/nik.dat','w') failed to open stream: No such file or directory
Warning fopen('/msg/nik.dat','w') failed to open stream: No such file or directory
Warning fopen('./msg/nik.dat','w') failed to open stream: No such file or directory
What is right.
herb2006
QUOTE(ugser @ Nov 6 2009, 04:33 AM) *
Text file is 'msg/nik.dat'.
Function file_exists('msg/nik.dat') return true.
Warning fopen('msg/nik.dat','w') failed to open stream: No such file or directory
Warning fopen('/msg/nik.dat','w') failed to open stream: No such file or directory
Warning fopen('./msg/nik.dat','w') failed to open stream: No such file or directory
What is right.


chmod("msg/nik.dat",0666); first! hunter.gif
ugser
QUOTE(herb2006 @ Nov 6 2009, 09:27 AM) *
chmod("msg/nik.dat",0666); first! hunter.gif


CODE
$f = "msg/nik.dat";
chmod($f,0666);
$fp = fopen($f,"w");
if (file_exist($f)==true){
//Warning: chmod() Operation not permitted
}
else
{
//Warning: chmod() Unable to access msg/nik.dat
//Warning: chmod() stat failed for msg/nik.dat
//Warning: fopen(msg/nik.dat) Permission denied
}

Where is mistake
For $f = "./nik.dat" - all good without chmod .
herb2006
QUOTE(ugser @ Nov 7 2009, 12:01 AM) *
Where is mistake
For $f = "./nik.dat" - all good without chmod .


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

herb2006
QUOTE(ugser @ Nov 9 2009, 04:06 AM) *
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.


rolleyes.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.