开发者

PHP opens file with too strict of permissions

开发者 https://www.devze.com 2023-01-29 23:40 出处:网络
When I open a file using fopen($fi开发者_如何学编程lename, \'w+\') (that is, reading and writing), it creates the file with permissions like this:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消