This is a discussion on [function.file-put-contents]: failed to open stream within the PHP Language forums, part of the PHP Programming Forums category; webguy262 wrote: > I'm trying to troubleshoot a membership script. The script is > attempting to write to a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
webguy262 wrote:
> I'm trying to troubleshoot a membership script. The script is > attempting to write to a file called .fdaccess. The function that's > throwing the error is in a file called htpasswd.php. Here's the > fuinction: > > function save($file=false){ > $fcontents = ""; > if($file == false) $file = $this->_path; > foreach(array_keys($this->users) as $user){ > $fcontents .= $user.":".$this->users[$user]."\n"; > } > if(file_put_contents($file, $fcontents)){ > $this->error = ''; > return true; > }else{ > $this->error = 'Couln\'t save the file!'; > return false; > } > } > > Here's the error... > > Warning: file_put_contents(/public_html/mylogins/extras/.fdaccess) > [function.file-put-contents]: failed to open stream: No such file or > directory in /home/freebnow/public_html/mylogins/admin/htpasswd.php on > line 111 > > This is line 111: if(file_put_contents($file, $fcontents)){ > > htpasswd.php is a class available here: http://www.apachelounge.com/forum/viewtopic.php?t=635 > > The file is in the path specified, and it is chmod 700. > > Any suggestions? > > > > What's the contents of $file? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
I'm trying to troubleshoot a membership script. The script is
attempting to write to a file called .fdaccess. The function that's throwing the error is in a file called htpasswd.php. Here's the fuinction: function save($file=false){ $fcontents = ""; if($file == false) $file = $this->_path; foreach(array_keys($this->users) as $user){ $fcontents .= $user.":".$this->users[$user]."\n"; } if(file_put_contents($file, $fcontents)){ $this->error = ''; return true; }else{ $this->error = 'Couln\'t save the file!'; return false; } } Here's the error... Warning: file_put_contents(/public_html/mylogins/extras/.fdaccess) [function.file-put-contents]: failed to open stream: No such file or directory in /home/freebnow/public_html/mylogins/admin/htpasswd.php on line 111 This is line 111: if(file_put_contents($file, $fcontents)){ htpasswd.php is a class available here: http://www.apachelounge.com/forum/viewtopic.php?t=635 The file is in the path specified, and it is chmod 700. Any suggestions? |
|
|||
|
webguy262 wrote:
> I'm trying to troubleshoot a membership script. The script is > attempting to write to a file called .fdaccess. The function that's > throwing the error is in a file called htpasswd.php. Here's the > fuinction: > > function save($file=false){ > $fcontents = ""; > if($file == false) $file = $this->_path; > foreach(array_keys($this->users) as $user){ > $fcontents .= $user.":".$this->users[$user]."\n"; > } > if(file_put_contents($file, $fcontents)){ > $this->error = ''; > return true; > }else{ > $this->error = 'Couln\'t save the file!'; > return false; > } > } > > Here's the error... > > Warning: file_put_contents(/public_html/mylogins/extras/.fdaccess) > [function.file-put-contents]: failed to open stream: No such file or > directory in /home/freebnow/public_html/mylogins/admin/htpasswd.php on > line 111 > > This is line 111: if(file_put_contents($file, $fcontents)){ > > htpasswd.php is a class available here: http://www.apachelounge.com/forum/viewtopic.php?t=635 > > The file is in the path specified, and it is chmod 700. > > Any suggestions? > > > chmod 700 isn't the right permissions unless PHP is running as the same owner as the file to which you're attempting to write, which is not always the case. If your script has to create the file, I believe the directory needs write/execute privileges for the containing dir. Try chmod 622 (gives write access to the world) or 666 (read and write). You can amend .htaccess or httpd.conf (if available to you) to forbid direct access to your file, which will work, regardless of file permissions. -- Curtis |