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
Return to the default flat view Create a new topic Submit Reply
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 previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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: Fri Sep 20 16:44:52 GMT 2024

Total time taken to generate the page: 0.04277 seconds