PHP:创建没有chmod()的只读文件

Tre*_*vor 0 php chmod

我的服务器上禁用了chmod(),但我仍然希望用户能够通过PHP创建只读文件,有没有办法这样做?

Aln*_*tak 6

你不能,因为不可能把任何东西放在只读文件中......

实际编辑,有一种方法:

<?php
  $u = umask(0377); // disables --wxrwxrwx permissions
  $f = fopen("test", "w");
  umask($u);
  fwrite($f, "this is a test\n");
  fclose($f);
?>

% php foo.php
% ls -l test
-r--------  1 xxx xxx  14 19 May 10:27 test
% cat test
this is a test
Run Code Online (Sandbox Code Playgroud)

umask即使基础目录条目是只读的,操作也允许您创建读/写文件描述符.