dqingn8836
2014-04-14 20:57
浏览 982
已采纳

PHP chmod():不允许操作,涉及safe_mode弃用?

I'm struggling a bit to grasp the concept of chmod() from PHP as the course I'm currently taking is a bit outdated and involves safe_mode. It states that as safe_mode is turned off, the restrictions to modify permissions with chmod() to a file when the owner is not the same as the one executing the command are removed. I'm working with PHP 5.5.9 in conjuncture with XAMPP, I've verified that the flags are turned off (just in case), but can't seem to get it working. As I execute the following PHP script:

echo "File permissions :" .  decoct(fileperms("file_permissions.php"));
chmod("file_permissions.php" ,0777);

I receive the following output :

Warning: chmod(): Operation not permitted

My permissions for the file are the following

-rwxrwxrwx@  1 joelhernandez  staff     24 Apr 14 06:59 file_permissions.php

And I've executed ps aux | grep httpd to confirm that the my webserver is operating under the user "daemon" .

As I change the file ownership to daemon:

-rwxrwxrwx@  1 daemon  staff     24 Apr 14 06:59 file_permissions.php

Everything works, I do not understand why as I had understood that with safe_mode turned off, file ownership would mean nothing, instead file permissions were the way to handle access.

图片转代码服务由CSDN问答提供 功能建议

我正在努力从PHP中把握 chmod()的概念 我目前正在采取的课程有点过时,涉及safe_mode。 它声明,当safe_mode关闭时,删除了当所有者与执行命令的所有者不同时,使用 chmod()将权限修改为文件的限制。 我正在使用PHP 5.5.9与XAMPP结合使用,我已经验证了标志已关闭(以防万一),但似乎无法使其正常工作。 当我执行以下PHP脚本时:

  echo“文件权限:”。  decoct(fileperms(“file_permissions.php”)); 
chmod(“file_permissions.php”,0777); 
   
 
 

我收到以下输出:

 警告:chmod():不允许操作
   
 
 

我对文件的权限如下 \ n

  -rwxrwxrwx @ 1 joelhernandez staff 24 Apr 14 06:59 file_permissions.php 
   
 
 

我已经执行了 ps aux | grep httpd 以确认我的网络服务器在用户“守护程序”下运行。

当我将文件所有权更改为守护程序时

  -rwxrwxrwx @ 1 daemon staff 24 Apr 14 06:59 file_permissions.php 
   
 
 

一切正常,我不明白为什么我已经理解,关闭safe_mode后,文件所有权将毫无意义,而文件权限是处理访问权限的方式。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douzhuo8312 2014-04-14 21:13
    已采纳

    The daemon user is not root, so it is not allowed to change the mode of a file owned by a different user. PHP safe_mode is not the cause here. The warning is telling you that the attempted operation failed because the web server user did not have permission to make the mode change.

    The operation succeeded after you manually changed the ownership of the file to daemon because users are allowed to change the mode of files they own.

    点赞 打赏 评论
  • doufan9290 2018-07-12 09:38

    add @ before chmod
    Example :

    <?php  
    $filePath = 'Your file path';
    if(!file_exists(dirname($filePath))) {
    mkdir(dirname($filePath), 0775, true);
    @chmod(dirname($filePath),0777);
    }
    ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题