file_put_contents not creating file [message #172271] |
Tue, 08 February 2011 22:07 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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.
|
|
|
|
|