By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Aug 25 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
js*******@attglobal.net
==================

Aug 25 '08 #2

P: n/a
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
Aug 25 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.