PHP opens file with too strict of permissions
When I open a file using fopen($fi开发者_如何学编程lename, 'w+')
(that is, reading and writing), it creates the file with permissions like this:
-rw-r--r-- 1 www-data www-data 0 2010-12-09 12:02 TransactionImport-7.txt
Then, when other processes try to open the file, they can't do it. How can I get the file to open with less strict permissions?
I can't change the permissions after I close the file because other programs need to read the file while it's still being written. When I try to change them before with chmod()
, it makes it so my script can't write to the file at all.
You can use touch
before fopen
with w+
such as
touch($filename);
chmod($filename, YOUR_PREFER_PERMISSION);
fopen($filename, 'w+');
OR
umask
- http://www.php.net/manual/en/function.umask.php
精彩评论