【问题标题】:What chmod permission to use when creating user group directory with PHP mkdir()使用 PHP mkdir() 创建用户组目录时使用什么 chmod 权限
【发布时间】:2013-01-06 11:16:41
【问题描述】:

-

  • 一个 PHP Web 应用程序,需要允许已登录的管理员上传和删除图像到 Web 文件夹,以获取特定记录。

  • 在 MySQL 数据库中创建记录时,还会在公共服务器上创建一个文件夹 - 使用 PHP mkdir() - 来保存该特定记录的图像。

  • 将有多个用户使用同一个应用程序,所有用户都需要向正在创建的文件夹添加和删除图像的权限。

  • 还需要继续通过 FTP 访问该文件夹。

所以我想总体而言,它需要可供登录用户访问 - 添加、编辑、删除、查看、FTP - 但公众无法访问。

我应该为此使用什么文件夹权限?

原因为什么?安全?可访问性?编辑能力?

谢谢。 问候。

【问题讨论】:

    标签: php permissions directory chmod mkdir


    【解决方案1】:

    使用 Web 界面上传文件时,您的上传目录需要可由 apache 用户写入。如果与文件的所有交互都将通过 Web 界面进行,您只需要担心 apache 用户,其他组将通过 Web 应用程序进行身份验证。

    如果您正在创建文件夹,然后允许用户和组从您需要创建组的服务器访问文件。在这种情况下,请创建一个管理员组。

    步骤:

    //make the admin group
    $ groupadd admin
    
    // make the folder for uploads
    $ sudo mkdir uploads
    
    // make the apache user (apache or www-data) the owner and the group admin
    $ chown apache.admin uploads
    
    // give the folder permission using the sticky bit
    // this will allow both apache and admin group to edit/add/delete in uploads
    $ chmod 7752 uploads
    
    // the sticky bit will maintain the group inside the uploads folder
    // try it out
    $ su apache
    $ cd uploads
    $ mkdir test
    $ touch newFile.txt
    
    // the new folder and new file should have admin as the group
    

    没有粘性位,上传中的新文件和文件夹将归 apache 和 apache 组所有。即... chmod 775 测试

    现在,当您在上传文件夹中创建新文件夹时,管理员组中的用户将拥有对它们的 ftp 访问权限

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-15
      • 2017-09-06
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      • 2020-07-12
      • 2015-05-02
      • 1970-01-01
      相关资源
      最近更新 更多