Welcome to WebmasterWorld Guest from 54.159.12.17

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP can't create files?

     

Scooter24

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

10+ Year Member



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

Frank_Rizzo

11:08 pm on Sep 10, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



have you checked that the directory you are writing too has the correct rights?

hpche

12:13 am on Sep 11, 2002 (gmt 0)

10+ Year Member



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.

Scooter24

1:55 am on Sep 11, 2002 (gmt 0)

10+ Year Member



What permissions do I need? Is 755 enough or do I need a 666? (if the directory is on my site)

ergophobe

9:37 pm on Sep 11, 2002 (gmt 0)

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




(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

Scooter24

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

10+ Year Member



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.

mrgym

2:39 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month