473,473 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

[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?

Aug 25 '08 #1
2 10079
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cherrish Vaidiyan | last post by:
hello scholars, i am just learning PHP. i have a small requirement in urgency.i want to create a functionality of archiving in which a user can upload any file through a browser to a location....
2
by: jon.berg | last post by:
I have a problem getting the file() function in PHP to work on several linux distributions, for example fedora core 3. For example file('http://someurl.com/') do not return the content of that...
11
by: Bryant Huang | last post by:
Hello! I would like to read in files, during run-time, which contain plain Python function definitions, and then call those functions by their string name. In other words, I'd like to read in...
3
by: Susan | last post by:
Hi all, I have several books on Javascript and, although they mention placing frequently used script functions in a central file and calling them from, there they don't explain how to call them....
1
by: kaiser | last post by:
Hello. I am trying to write a program that continues to read the last line of a txt file until a stop button is clicked. while (ContinueLoop == true ) { while ((LastLine = file.ReadLine()) !=...
6
by: mygoogleaccount | last post by:
Hi, may be someone could help me ? i need to use cyrillic letters in a php application. I changed everything to UTF-8 and it works fine. The only problem are CYRILLIC SMALL LETTER ES...
2
by: r.knipscheer | last post by:
Hi, i've written a function to check if an image on a server exists: i send the url to check to the function and check it with: $file = @file ($url); if ($file) { this works ok, as long as...
7
by: danielbaars | last post by:
Hello, I'm almost a complete newbie to using PHP and I was hoping one of you guys can point me in the right direction. I'm working on a site for a brand of handmade fruit juice and it only needs...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
1
by: faultykid | last post by:
I would like to store a variable then call it back later. I have a variable on line 198 www = ''+this._ad.clickUrl+''; and on line 321 i try document.write(www);
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.