Function Fopen |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Web Design & Development Server Side Scripting PHP |
||
![]() |
Function Fopen |
||
Nov 6 2009, 04:33 AM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 3 Joined: 6-November 09 Member No.: 117,173 |
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. |
|
|
Nov 6 2009, 09:27 AM
Post
#2
|
|
![]() Member ![]() ![]() Group: Members Posts: 72 Joined: 11-October 09 From: GuangZhou,China Member No.: 113,472 |
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! |
|
|
Nov 7 2009, 12:01 AM
Post
#3
|
|
|
Newbie ![]() Group: Members Posts: 3 Joined: 6-November 09 Member No.: 117,173 |
chmod("msg/nik.dat",0666); first! 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 . |
|
|
Nov 8 2009, 06:01 AM
Post
#4
|
|
![]() Member ![]() ![]() Group: Members Posts: 72 Joined: 11-October 09 From: GuangZhou,China Member No.: 113,472 |
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-) |
|
|
Nov 9 2009, 04:06 AM
Post
#5
|
|
|
Newbie ![]() Group: Members Posts: 3 Joined: 6-November 09 Member No.: 117,173 |
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; } |
|
|
Nov 9 2009, 07:56 AM
Post
#6
|
|
![]() Member ![]() ![]() Group: Members Posts: 72 Joined: 11-October 09 From: GuangZhou,China Member No.: 113,472 |
|
|
|
![]() |
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 21st November 2009 - 12:40 AM |