【问题标题】:php creates folder with 341 permissionsphp 创建具有 341 权限的文件夹
【发布时间】:2011-04-16 19:40:25
【问题描述】:

在谷歌上没有找到答案,所以这是我在尝试其他方法之前的最后一次尝试。

我有一个这样的脚本:

        // get current year and month
        $cur_year = date('Y');
        $cur_month = date('m');
        $long_type = $this->getFile_longtype();

        $folder = $_SERVER['DOCUMENT_ROOT']."/".FOLDER_CMS."/uploads/$long_type/$cur_year/$cur_month";

        // check whether the folder exists
        if(!is_dir($folder)){

            // try to make the folder recursively
            if(!mkdir($folder,"0777",true)){

                logError($message, __FILE__, __LINE__);
                throw new Exception("Failure creating proper directories");

            }

        }

为了让它工作,我将上传目录及其所有文件和目录修改为 777(这里有更好的建议吗?)

long 类型的计算结果为“images”,这是一个已经在服务器上创建的目录。

现在,脚本创建以 year 命名的文件夹,权限为 341。这不是我想要的,因为它终止了递归文件夹的构建或阻止了它的内容。

有什么帮助或建议吗?

php版本:5.2.5

配置命令 : './configure' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-ftp' '--enable -gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-soap' '--enable -sockets' '--enable-wddx' '--enable-zip' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with- bz2' '--with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '- -with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libexpat-dir =/usr' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with -mhash=/opt/mhash/''--with-mssql=/usr/local/freetds''--with-mysql=/usr''--with-mysql-sock=/var/lib/mysql/mysql .sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--wit h-pspell' '--with-sqlite=shared' '--with-tidy=/opt/tidy/' '--with-ttf' '--with-xmlrpc' '--with-xpm-dir=/ usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr'

【问题讨论】:

    标签: php permissions chmod mkdir


    【解决方案1】:

    不要使用字符串“0777”,使用 0777。

    【讨论】:

      【解决方案2】:

      正如 Alex 所提到的,您也应该输入 OCTAL 值而不是 STRING,出于安全原因从不授予文件夹的完全权限,而改用 0755

      【讨论】:

      • 我应该授予我将存储在这些文件夹中的文件什么权限?
      【解决方案3】:

      真正的权限取决于 mkdir 的参数和umask。从赋予 mkdir 的权限中减去 umask。在执行 mkdir 之前尝试将您的 umask 设置为 0。

      【讨论】:

      • 这并没有改变任何东西,只是权限从 341 变为 441 或类似的东西。
      猜你喜欢
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 2016-08-14
      相关资源
      最近更新 更多