Jump to content

Writing to a file


supertrucker

Recommended Posts

I'm having trouble opening a file for output. I can open the file to read it, eg:function test1($filename){ $file=fopen($filename,"r"); ..read file, etc. fclose($file);}but when I open the same file in write mode, it continually returns FALSE, why? Eg:function test2($filename){ $file=fopen($filename,"w"); if ($file==FALSE) { echo "Why oh why!!??"; } .... fclose($file);}

Link to comment
Share on other sites

well, I tried it (chmod) but it's still not working. Here's my actual source:function saveUserData($userinfo){ include("global_setup.php"); $filename=$usersbase.$userinfo['userid'].'.usr'; chmod($usersbase,0666); chmod($filename,0666); $_SESSION['msg']=$filename; // Vars in $userinfo (from edit users): // userid, pass1, pass2, currentPassword // email, joindate,accesslevel $password=$userinfo['currentPassword']; $len1=strlen($userinfo['pass1']); $len2=strlen($userinfo['pass2']); // Below is a simple "dumb" check. If the // length of pass1 and pass2 are greater than // zero, then pass1 is the new password. // Otherwise, default to old. if (($len1 > 0) && ($len2 > 0)) { $password=$userinfo['pass1']; } $file = fopen($filename,"w"); if ($file==FALSE) {$_SESSION['msg']=$_SESSION['msg'].' Open failure. '.$t;} fputs($file, '/= Dummy line.'); fputs($file, 'password='.$password); fputs($file, 'email='.$userinfo['email']); fputs($file, 'joindate='.$userinfo['joindate']); fputs($file, 'accesslevel='.$userinfo['accesslevel']); fclose($file);}

Link to comment
Share on other sites

It also never hurts to print the filename and see what you're asking it to open.
Thanks for your help! How do I enable error messaging on the fly, as I don't have access to my php.ini file, I just assume it's in there..I will try your suggestions, too, as error messages would definately help me in debugging!
Link to comment
Share on other sites

ini_set("display_errors", 1);error_reporting(E_ALL);
Ok, now that I can see my bugs, here is what the output of the chmod function resulted in:Warning: chmod() [function.chmod]: Operation not permitted in /home/account/public_html/zerorubbish/files.php on line 123Any advice on that error message, as I'm really confused now?!!Thanks!ST
Link to comment
Share on other sites

Well, obviously, your host doesn't allow you to alter permissions. Forget about chmod(), or try a different persmission mask.

Link to comment
Share on other sites

Well, obviously, your host doesn't allow you to alter permissions. Forget about chmod(), or try a different persmission mask.
Well, any suggestions, as I'm just not that experienced in the language...
Link to comment
Share on other sites

What happened when you tried the suggestions in posts #5 and #6?
Same thing as before. Keeps telling me that there is a rights issue.
Link to comment
Share on other sites

Maybe you need to check out FAQs on your host's website, maybe even email their support people for help. It sounds like you have a major rights issue that may have to be set at the admin level.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...