【问题标题】:PHP cannot assign rights on directoryPHP 无法分配目录权限
【发布时间】:2015-06-02 11:31:59
【问题描述】:

我想在我的页面脚本中创建一个directory

$critere = array();
$critere["bien_code"] = read_post_int("pk");
$name = "parcelle_". $photo->lireBienPhotoSeq().".png";
if ( ! file_exists (RP_PHOTO_PARCELLE) )
    mkdir(RP_PHOTO_PARCELLE, 0777, true);
$dest = RP_PHOTO_PARCELLE . $name;

问题是当我在服务器上创建ls -l 时,directoryrights 只是 755 !那么为什么目录的权限不是 777 呢?

【问题讨论】:

标签: php linux ubuntu


【解决方案1】:

创建目录后尝试使用chmod

所以你的代码应该是这样的

$critere = array();
$critere["bien_code"] = read_post_int("pk");
$name = "parcelle_". $photo->lireBienPhotoSeq().".png";
if ( ! file_exists (RP_PHOTO_PARCELLE) )
    mkdir(RP_PHOTO_PARCELLE, 0777, true);
chmod(RP_PHOTO_PARCELLE, 0777); //<------ new line added for giving access
$dest = RP_PHOTO_PARCELLE . $name;

注意: 提供对文件夹的 0777 访问权限是个坏主意。它涉及高安全风险。有关风险,请参阅herehere 如果您了解风险并且仍然需要授予 0777 访问权限,请使用它,否则请尽量避免它

【讨论】:

  • 我想将其设为 777,因为在我的项目中有一个 Android 应用程序可以将照片发布到此目录!所以目录的权限应该是777!
【解决方案2】:

你应该使用 chmod

// more code
chmod($path, 0755);

or 
chmod($path, 0777);

【讨论】:

    【解决方案3】:

    还必须为此处理进程umask:

    umask(0);
    mkdir(RP_PHOTO_PARCELLE, 0777, true);
    

    但正如 cmets 中所述:这是不好的做法。应尽可能避免这种许可模式。

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-04
      • 2017-12-21
      • 2016-03-24
      • 2013-07-30
      相关资源
      最近更新 更多