mattal999 Posted October 13, 2007 Share Posted October 13, 2007 i have this code: <?php session_start(); $file = $_POST['file']; $text = $_POST['content']; $username = $_SESSION['userName']; chdir($username); $handle = fopen("$file", "x+"); chmod("$file", 0777); fwrite($handle, $text); chmod("$file", 0755); echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=" . $file . "'>Here</a>"; ?> which returns this (posted filename = lol.php): <br /> <b>Warning</b>: fopen() [<a href='function.fopen'>function.fopen</a>]: SAFE MODE Restriction in effect. The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/mattal999 owned by uid/gid 33/33 in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>7</b><br /> <br /> <b>Warning</b>: fopen(lol.php) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>7</b><br /> <br /> <b>Warning</b>: chmod() [<a href='function.chmod'>function.chmod</a>]: Unable to access lol.php in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>8</b><br /> <br /> <b>Warning</b>: chmod() [<a href='function.chmod'>function.chmod</a>]: No such file or directory in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>8</b><br /> <br /> <b>Warning</b>: fwrite(): supplied argument is not a valid stream resource in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>9</b><br /> <br /> <b>Warning</b>: chmod() [<a href='function.chmod'>function.chmod</a>]: Unable to access lol.php in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>10</b><br /> <br /> <b>Warning</b>: chmod() [<a href='function.chmod'>function.chmod</a>]: No such file or directory in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>10</b><br /> File lol.php created! Edit it Here help plz! Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/ Share on other sites More sharing options...
marcus Posted October 13, 2007 Share Posted October 13, 2007 Use a full path. $file = "/path/to/folder/where/etc/" . $_POST['file']; //etc... # when you chmod it, chmod $handle Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-368739 Share on other sites More sharing options...
mattal999 Posted October 13, 2007 Author Share Posted October 13, 2007 nope it still doesn't work... Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-368743 Share on other sites More sharing options...
marcus Posted October 13, 2007 Share Posted October 13, 2007 CHMOD the folder of the files to 0777 Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-368744 Share on other sites More sharing options...
mattal999 Posted October 13, 2007 Author Share Posted October 13, 2007 i already have... i was thinking... is there a way to copy the file: new2.php, from the sites/ folder to sites/$username? Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-368745 Share on other sites More sharing options...
kratsg Posted October 13, 2007 Share Posted October 13, 2007 Something's telling me it's your php.ini settings. You do have safe mode on meaning some accessibility is limited. Also, your quoting is wrong for this line: echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=" . $file . "'>Here</a>"; It should be: echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>"; Since you already have echoed out in double quotes, variables don't need to be added on, ie. echo "Hello, my name is ".$var." and I am saying hello."; echo "Hello, my name is $var and I am saying hello."; echo "Hello, my name is '$var' and I am saying hello." All three will echo the variable correctly. Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-368757 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 well, i changed that... any other ideas on how to make it work... if i ask my hoster to take off safe mode for me then do you think it will make a difference? thanks Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369173 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 nobody got a solution? Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369205 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 Yeah i got one, CAUSE: $handle = fopen("$file", "x+"); Warning: fopen() [<a href='function.fopen'>function.fopen[/url]]: SAFE MODE Restriction in effect. The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/mattal999 owned by uid/gid 33/33 in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 7 FIX: turn off SAFE MODE Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369208 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 whats the great thing about SAFE MODE anyway? what will happen if my hoster will turn it off? ive requested it and i am awaiting a reply... Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369214 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 SAFE MODE = more secure.. LMAO.. well they say that.. why are you trying to access a file create by another user anyway ? if they where the same your be okay even with safe mode! Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369224 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 well basically im making a web hosting system... its flat file based... when a user signs up, it makes a new folder called (their username) and registers them in the username and pwd system. and i want them to create a new file in their folder but i cannot do this by using a file in sites/ when their folder is sites/(username)/. help please... i have tried many things. Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369261 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 Like this! assuming that the folder sites/test/ exists <?php $username = "test"; $filename = "sites/$username/"; $somecontent = "Blar\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'w+')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369265 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 hmmm... new code: <?php session_start(); $username = $_SESSION['userName']; $file = $_POST['file]; $filename = "$username/$file"; $somecontent = "This is a new file"; if (is_writable($filename)) { if (!$handle = fopen($filename, 'x+')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> new error: Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 8 EDIT: fixed error, missing a '. now i get: The file mattal999/new9.php is not writable Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369268 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 nobody? EDIT: new code: <?php session_start(); $username = $_SESSION['userName']; $file = $_POST['file']; $filename = "$username/$file"; $somecontent = "This is a new file"; chmod($username, 0777); if (is_writable($filename)) { if (!$handle = fopen($filename, 'w+')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369275 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 please help, this is stressing me out like mad. it's just not possible to write to another folder in the current directory using any code at all... there has to be some way! Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369284 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 try this <?php session_start(); $username = $_SESSION['userName']; $file = $_POST['file']; $curpath = dirname(__FILE__); $filename = "$curpath/$username/$file"; $somecontent = "This is a new file"; echo (chmod($curpath."/".$username, 0777))?"":"chmod failed"; if (is_writable($filename)) { if (!$handle = fopen($filename, 'w+')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> or use can use chdir($username); Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369296 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 nope and ive tried chdir b4... this isnt possible is it?... Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369318 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 this works for me <?php $user = "Test"; $file = "MyFile.txt"; $CurDir = dirname(__FILE__); $somecontent = "TEST"; $NewDir = "$CurDir/$user"; $filepath = $NewDir."/".$file; if (!file_exists($NewDir) && !is_dir($NewDir) ) mkdir($NewDir, 0755); if( is_dir($NewDir) ) { if (is_writable($NewDir)) { if (!$handle = fopen($filepath, 'w+')) { echo "Cannot open file ($filepath)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filepath)"; exit; } echo "Success, wrote ($somecontent) to file ($filepath)"; fclose($handle); } else { echo "The file $filepath is not writable"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369338 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 nope... code: <?php session_start(); $user = $_SESSION['userName']; $file = $_POST['file']; $CurDir = dirname(__FILE__); $somecontent = "TEST"; $NewDir = "$CurDir/$user"; $filepath = $NewDir."/".$file; if (!file_exists($NewDir) && !is_dir($NewDir) ) mkdir($NewDir, 0755); if( is_dir($NewDir) ) { if (is_writable($NewDir)) { if (!$handle = fopen($filepath, 'x+')) { echo "Cannot open file ($filepath)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filepath)"; exit; } echo "Success, wrote ($somecontent) to file ($filepath)"; fclose($handle); } else { echo "The file $filepath is not writable"; } } ?> returns error: Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/mattal999 owned by uid/gid 33/33 in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16 Warning: fopen(/home/users/uks51756/html/games4uonline.com/sites/mattal999/test2.phphp) [function.fopen]: failed to open stream: No such file or directory in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16 Cannot open file (/home/users/uks51756/html/games4uonline.com/sites/mattal999/test2.phphp) its really not possible... Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369401 Share on other sites More sharing options...
mattal999 Posted October 14, 2007 Author Share Posted October 14, 2007 i have absolutely no idea how to make this work... i am |-| this close to giving up! please, any last suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369407 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 remove the user folder, and try my script again Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369453 Share on other sites More sharing options...
mattal999 Posted October 15, 2007 Author Share Posted October 15, 2007 i took out the user folder lolol after registering and then ran script: Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/lolol owned by uid/gid 33/33 in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16 Warning: fopen(/home/users/uks51756/html/games4uonline.com/sites/lolol/test9997.php) [function.fopen]: failed to open stream: No such file or directory in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16 Cannot open file (/home/users/uks51756/html/games4uonline.com/sites/lolol/test9997.php) Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369949 Share on other sites More sharing options...
mattal999 Posted October 15, 2007 Author Share Posted October 15, 2007 yay! i found out how to turn off safe mode with my hosters and now it works fine! cheers MadTechie! you are a gr8 person thanks again Quote Link to comment https://forums.phpfreaks.com/topic/73118-can-you-find-the-cause/#findComment-369959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.