supertrucker Posted March 20, 2008 Share Posted March 20, 2008 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 More sharing options...
jlhaslip Posted March 20, 2008 Share Posted March 20, 2008 Check that the file and folder permissions are set for writing? chmod to 666 as a start. Link to comment Share on other sites More sharing options...
supertrucker Posted March 20, 2008 Author Share Posted March 20, 2008 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 More sharing options...
justsomeguy Posted March 20, 2008 Share Posted March 20, 2008 Make sure error messages are enabled and are being displayed. Don't use chmod on a directory, you should only use that on a file. Link to comment Share on other sites More sharing options...
jeffman Posted March 20, 2008 Share Posted March 20, 2008 To isolate the problem, try opening a file named with a string literal. If that works, the problem is in your naming routine, not the file system. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 20, 2008 Share Posted March 20, 2008 It also never hurts to print the filename and see what you're asking it to open. Link to comment Share on other sites More sharing options...
supertrucker Posted March 20, 2008 Author Share Posted March 20, 2008 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 More sharing options...
justsomeguy Posted March 20, 2008 Share Posted March 20, 2008 ini_set("display_errors", 1);error_reporting(E_ALL); Link to comment Share on other sites More sharing options...
supertrucker Posted March 21, 2008 Author Share Posted March 21, 2008 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 More sharing options...
boen_robot Posted March 21, 2008 Share Posted March 21, 2008 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 More sharing options...
supertrucker Posted March 21, 2008 Author Share Posted March 21, 2008 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 More sharing options...
jeffman Posted March 21, 2008 Share Posted March 21, 2008 What happened when you tried the suggestions in posts #5 and #6? Link to comment Share on other sites More sharing options...
supertrucker Posted March 21, 2008 Author Share Posted March 21, 2008 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 More sharing options...
jeffman Posted March 21, 2008 Share Posted March 21, 2008 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 More sharing options...
zachary Posted March 22, 2008 Share Posted March 22, 2008 I kind of agree w/ them, can you chmod, without using PHP? Do you have a file manager, that you can chmod from? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.