【发布时间】:2013-05-16 08:43:16
【问题描述】:
您好,我正在运行一个 centos 服务器,我想知道如何设置由 php 创建的新文件(如 fopen)的默认 chmod。目前它正在执行 644 但我想要 666 那么我在哪里可以指定此设置?
【问题讨论】:
您好,我正在运行一个 centos 服务器,我想知道如何设置由 php 创建的新文件(如 fopen)的默认 chmod。目前它正在执行 644 但我想要 666 那么我在哪里可以指定此设置?
【问题讨论】:
您可以在 fopen() 调用之前立即使用 umask(),但如果您在多线程服务器上,则不应使用 umask - 它会更改所有线程的掩码(例如,此更改位于进程级别),而不仅仅是您将要在其中使用 fopen() 的那个。
例如
$old = umask(000);
fopen('foo.txt', 'w'); // creates a 0666 file
umask($old) // restore original mask
然而,事后简单地 chmod() 会更容易:
fopen('foo.txt', 'w'); // create a mode 'who cares?' file
chmod('foo.txt', 0666); // set it to 0666
【讨论】:
umask($old),对吧?或者umask 调用是否会进行永久性更改?
与 Linux 一样,PHP 有一个 chmod() 命令,可以调用该命令来更改文件权限。
在此处查看文档:http://php.net/manual/en/function.chmod.php
对于默认设置,您可以尝试Patrick Fisher 在此处声明的内容:Setting the umask of the Apache user
[root ~]$ echo "umask 000" >> /etc/sysconfig/httpd
[root ~]$ service httpd restart
【讨论】: