Bluehost.com Web Hosting $6.95

[function.file-put-contents]: failed to open stream

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-25-2008
Jerry Stuckle
 
Posts: n/a
Default Re: [function.file-put-contents]: failed to open stream

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
==================

Reply With Quote
  #2 (permalink)  
Old 08-25-2008
webguy262
 
Posts: n/a
Default [function.file-put-contents]: failed to open stream

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?



Reply With Quote
  #3 (permalink)  
Old 08-26-2008
Curtis
 
Posts: n/a
Default Re: [function.file-put-contents]: failed to open stream

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:18 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0