FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » file_put_contents not creating file
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
file_put_contents not creating file [message #172271] Tue, 08 February 2011 22:07 Go to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
Isn't this supposed to append OR create?

$file = "/home/mydomain/users/username/text.dat";
$post = "Test";

file_put_contents($file, $post, FILE_APPEND | LOCK_EX);

What's happening is, if the file already exists, then it appends with
no problem. But if it doesn't, then I'm getting this error:

Warning: file_put_contents(/home/mydomain/users/username/text.dat)
[function.file-put-contents]: failed to open stream: Permission denied
in/home/gowilkes/public_html/test.php on line 58

// Line 58 is the file_put_contents() line

I double checked that the directory path does exist. The permission
set for the directory is 0755, with owner/group set to 32007/32009.

TIA,

Jason
Re: file_put_contents not creating file [message #172273 is a reply to message #172271] Tue, 08 February 2011 22:19 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
On Feb 8, 5:07 pm, jwcarlton <jwcarl...@gmail.com> wrote:
> Isn't this supposed to append OR create?
>
> $file = "/home/mydomain/users/username/text.dat";
> $post = "Test";
>
> file_put_contents($file, $post, FILE_APPEND | LOCK_EX);
>
> What's happening is, if the file already exists, then it appends with
> no problem. But if it doesn't, then I'm getting this error:
>
> Warning: file_put_contents(/home/mydomain/users/username/text.dat)
> [function.file-put-contents]: failed to open stream: Permission denied
> in/home/gowilkes/public_html/test.php on line 58
>
> // Line 58 is the file_put_contents() line
>
> I double checked that the directory path does exist. The permission
> set for the directory is 0755, with owner/group set to 32007/32009.
>
> TIA,
>
> Jason

Nevermind, now that I typed it I realized the answer; PHP is not
running as Group, so I'm sure that I need the directory to be 0666 or
0777, not 0755.

Do you guys know a way to modify PHP so that it runs as Group instead
of Owner?

Or, not a PHP topic, but do you know a Linux command that will quickly
change the permission of 90,000 directories?
Re: file_put_contents not creating file [message #172275 is a reply to message #172271] Tue, 08 February 2011 22:58 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
jwcarlton wrote:
> Isn't this supposed to append OR create?
>
> $file = "/home/mydomain/users/username/text.dat";
> $post = "Test";
>
> file_put_contents($file, $post, FILE_APPEND | LOCK_EX);
>
> What's happening is, if the file already exists, then it appends with
> no problem. But if it doesn't, then I'm getting this error:
>
> Warning: file_put_contents(/home/mydomain/users/username/text.dat)
> [function.file-put-contents]: failed to open stream: Permission denied
> in/home/gowilkes/public_html/test.php on line 58
>
> // Line 58 is the file_put_contents() line
>
> I double checked that the directory path does exist. The permission
> set for the directory is 0755, with owner/group set to 32007/32009.
>
> TIA,
>
> Jason
So what permissions is PHP running with then? sounds like apache (for
example) doesn't have create perms in the directory.
Re: file_put_contents not creating file [message #172276 is a reply to message #172273] Tue, 08 February 2011 23:00 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
jwcarlton wrote:
> On Feb 8, 5:07 pm, jwcarlton <jwcarl...@gmail.com> wrote:
>> Isn't this supposed to append OR create?
>>
>> $file = "/home/mydomain/users/username/text.dat";
>> $post = "Test";
>>
>> file_put_contents($file, $post, FILE_APPEND | LOCK_EX);
>>
>> What's happening is, if the file already exists, then it appends with
>> no problem. But if it doesn't, then I'm getting this error:
>>
>> Warning: file_put_contents(/home/mydomain/users/username/text.dat)
>> [function.file-put-contents]: failed to open stream: Permission denied
>> in/home/gowilkes/public_html/test.php on line 58
>>
>> // Line 58 is the file_put_contents() line
>>
>> I double checked that the directory path does exist. The permission
>> set for the directory is 0755, with owner/group set to 32007/32009.
>>
>> TIA,
>>
>> Jason
>
> Nevermind, now that I typed it I realized the answer; PHP is not
> running as Group, so I'm sure that I need the directory to be 0666 or
> 0777, not 0755.
>
> Do you guys know a way to modify PHP so that it runs as Group instead
> of Owner?
>
> Or, not a PHP topic, but do you know a Linux command that will quickly
> change the permission of 90,000 directories?

chmod -R
Re: file_put_contents not creating file [message #172278 is a reply to message #172275] Wed, 09 February 2011 02:49 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
On Feb 8, 5:58 pm, The Natural Philosopher <t...@invalid.invalid>
wrote:
> jwcarlton wrote:
>> Isn't this supposed to append OR create?
>
>> $file = "/home/mydomain/users/username/text.dat";
>> $post = "Test";
>
>> file_put_contents($file, $post, FILE_APPEND | LOCK_EX);
>
>> What's happening is, if the file already exists, then it appends with
>> no problem. But if it doesn't, then I'm getting this error:
>
>> Warning: file_put_contents(/home/mydomain/users/username/text.dat)
>> [function.file-put-contents]: failed to open stream: Permission denied
>> in/home/gowilkes/public_html/test.php on line 58
>
>> // Line 58 is the file_put_contents() line
>
>> I double checked that the directory path does exist. The permission
>> set for the directory is 0755, with owner/group set to 32007/32009.
>
>> TIA,
>
>> Jason
>
> So what permissions is PHP running with then? sounds like apache (for
> example) doesn't have create perms in the directory.

It looks like PHP (under Apache 2.0.63) is creating as 0644, with
owner/group set to 99/99. Perl is also creating as 0644, but with
owner/group set to 32007/32009.

Most of the text files I'm using are only accessed by PHP, but the
"private message" section is used by both Perl and PHP, so I'm now
having a permission issue. I crossed this barrier with Session
variables that were set by PHP by changing the permission like this:

$sess_file = "/tmp/sess_" . session_id();
if (is_file($sess_file)) chmod($sess_file, 0644);


I'm confused as heck, to be honest. I changed the parent directory to
0777, and the Perl script that creates the directories says:

mkdir("$basepath/$users_path/$user", 0777);

But still, the new directories that are created are still being set to
0755. What??? That's a thread for a different NG, though.

I guess the question at this point is, how can I modify PHP so that it
can read files with permission 0644, owner/group = 32007/32009, in a
directory with permission 0777, o/g 32007/32009?
Re: file_put_contents not creating file [message #172283 is a reply to message #172278] Wed, 09 February 2011 04:39 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
On Feb 8, 9:49 pm, jwcarlton <jwcarl...@gmail.com> wrote:
> On Feb 8, 5:58 pm, The Natural Philosopher <t...@invalid.invalid>
> wrote:
>
>
>
>> jwcarlton wrote:
>>> Isn't this supposed to append OR create?
>
>>> $file = "/home/mydomain/users/username/text.dat";
>>> $post = "Test";
>
>>> file_put_contents($file, $post, FILE_APPEND | LOCK_EX);
>
>>> What's happening is, if the file already exists, then it appends with
>>> no problem. But if it doesn't, then I'm getting this error:
>
>>> Warning: file_put_contents(/home/mydomain/users/username/text.dat)
>>> [function.file-put-contents]: failed to open stream: Permission denied
>>> in/home/gowilkes/public_html/test.php on line 58
>
>>> // Line 58 is the file_put_contents() line
>
>>> I double checked that the directory path does exist. The permission
>>> set for the directory is 0755, with owner/group set to 32007/32009.
>
>>> TIA,
>
>>> Jason
>
>> So what permissions is PHP running with then? sounds like apache (for
>> example) doesn't have create perms in the directory.
>
> It looks like PHP (under Apache 2.0.63) is creating as 0644, with
> owner/group set to 99/99. Perl is also creating as 0644, but with
> owner/group set to 32007/32009.
>
> Most of the text files I'm using are only accessed by PHP, but the
> "private message" section is used by both Perl and PHP, so I'm now
> having a permission issue. I crossed this barrier with Session
> variables that were set by PHP by changing the permission like this:
>
> $sess_file = "/tmp/sess_" . session_id();
> if (is_file($sess_file)) chmod($sess_file, 0644);
>
> I'm confused as heck, to be honest. I changed the parent directory to
> 0777, and the Perl script that creates the directories says:
>
> mkdir("$basepath/$users_path/$user", 0777);
>
> But still, the new directories that are created are still being set to
> 0755. What??? That's a thread for a different NG, though.
>
> I guess the question at this point is, how can I modify PHP so that it
> can read files with permission 0644, owner/group = 32007/32009, in a
> directory with permission 0777, o/g 32007/32009?

Just to make it more interesting...

The file that I'm writing to is USUALLY created in Perl, and I change
the permission to 0666:

if (! -e "$file") {
open TEMP, ">>$file";
close TEMP;
}
chmod 0666, "$file";


If it's written this way, then in PHP, I can append to it.

However, I can't seem to create the file in PHP.
Re: file_put_contents not creating file [message #172287 is a reply to message #172273] Wed, 09 February 2011 10:19 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 08/02/11 22:19, jwcarlton wrote:

> Or, not a PHP topic, but do you know a Linux command that will quickly
> change the permission of 90,000 directories?

chown and chmod both support recursive application, find might allow
finer tuning.

Rgds

Denis McMahon
Re: file_put_contents not creating file [message #172288 is a reply to message #172278] Wed, 09 February 2011 12:00 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
jwcarlton wrote:
> On Feb 8, 5:58 pm, The Natural Philosopher <t...@invalid.invalid>
> wrote:
>> jwcarlton wrote:
>>> Isn't this supposed to append OR create?
>>> $file = "/home/mydomain/users/username/text.dat";
>>> $post = "Test";
>>> file_put_contents($file, $post, FILE_APPEND | LOCK_EX);
>>> What's happening is, if the file already exists, then it appends with
>>> no problem. But if it doesn't, then I'm getting this error:
>>> Warning: file_put_contents(/home/mydomain/users/username/text.dat)
>>> [function.file-put-contents]: failed to open stream: Permission denied
>>> in/home/gowilkes/public_html/test.php on line 58
>>> // Line 58 is the file_put_contents() line
>>> I double checked that the directory path does exist. The permission
>>> set for the directory is 0755, with owner/group set to 32007/32009.
>>> TIA,
>>> Jason
>> So what permissions is PHP running with then? sounds like apache (for
>> example) doesn't have create perms in the directory.
>
> It looks like PHP (under Apache 2.0.63) is creating as 0644, with
> owner/group set to 99/99. Perl is also creating as 0644, but with
> owner/group set to 32007/32009.
>
> Most of the text files I'm using are only accessed by PHP, but the
> "private message" section is used by both Perl and PHP, so I'm now
> having a permission issue. I crossed this barrier with Session
> variables that were set by PHP by changing the permission like this:
>
> $sess_file = "/tmp/sess_" . session_id();
> if (is_file($sess_file)) chmod($sess_file, 0644);
>
>
> I'm confused as heck, to be honest. I changed the parent directory to
> 0777, and the Perl script that creates the directories says:
>
> mkdir("$basepath/$users_path/$user", 0777);
>
> But still, the new directories that are created are still being set to
> 0755. What??? That's a thread for a different NG, though.
>

Stickies set on parent directory?

> I guess the question at this point is, how can I modify PHP so that it
> can read files with permission 0644, owner/group = 32007/32009, in a
> directory with permission 0777, o/g 32007/32009?

that should work, for reading.
Re: file_put_contents not creating file [message #172291 is a reply to message #172288] Thu, 10 February 2011 21:53 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> Stickies set on parent directory?

What do you mean by "stickies"?
Re: file_put_contents not creating file [message #172292 is a reply to message #172291] Thu, 10 February 2011 21:58 Go to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Feb 10, 9:53 pm, jwcarlton <jwcarl...@gmail.com> wrote:
>> Stickies set on parent directory?
>
> What do you mean by "stickies"?

http://lmgtfy.com/?q=linux+permissions+stickies
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Will this work?
Next Topic: need help to develop 2 language english and french
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 03:55:08 GMT 2024

Total time taken to generate the page: 0.03561 seconds