Welcome to WebmasterWorld Guest from 50.17.117.221

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP can't create files?

     
10:24 pm on Sep 10, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Aug 2, 2002
posts:212
votes: 0


My provider's server supports PHP 4, but I can't create a new file with a PHP script. Is it something my provider set or is there a way to create a file in PHP (such as with a "fcreate" function)?
11:08 pm on Sept 10, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 17, 2002
posts:1181
votes: 5


have you checked that the directory you are writing too has the correct rights?
12:13 am on Sept 11, 2002 (gmt 0)

New User

10+ Year Member

joined:Aug 23, 2002
posts:25
votes: 0


You can use fopen - [php.net...] - to create a file. You'll need to check the correct permissions on the script and directory are set though, or you'll end up with 'Permission Denied' errors.
1:55 am on Sept 11, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Aug 2, 2002
posts:212
votes: 0


What permissions do I need? Is 755 enough or do I need a 666? (if the directory is on my site)
9:37 pm on Sept 11, 2002 (gmt 0)

Moderator

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8137
votes: 95



(if the directory is on my site)

I think the deal is that you need correct permissions for the PHP process, not for you, and the PHP process is not the owner of the directory. So you probably need at least group write permission (665 or 765) but probably 666 or 766. Try 665 first, then 666. If you have to grant public write to write the file, what I have done is surround the file write line with chmods and change the perms, write the file, then take away public write. Not the best, but it's better than nothing.

Tom

12:06 pm on Sept 12, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Aug 2, 2002
posts:212
votes: 0


Well, I tried that yesterday (surrounding the fwrite with chmods) and it didn't work. The PHP script wasn't allowed to chmod the file or the directory. I'll have to talk with my provider about this.
2:39 pm on Sept 12, 2002 (gmt 0)

New User

10+ Year Member

joined:Sept 12, 2002
posts:4
votes: 0


Here's the deal. The "user" trying to write the files is your webserver. If the webserver is run as "nobody" then "nobody" would need to have rights to write files whereever your script calls for them.