php创建具有341权限的文件夹

发布于 2024-09-24 22:48:38 字数 2042 浏览 5 评论 0原文

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

我有一个这样的脚本:

        // 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(这里有更好的建议?)

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

现在,该脚本创建以年份命名且权限为 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=共享' ' --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=共享' '--with-pdo-sqlite=共享' '--with-png-dir=/usr' '--with-pspell' '--with-sqlite=共享' ' --with-tidy=/opt/tidy/' '--with-ttf' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/ ' '--with-zlib' '--with-zlib-dir=/usr'

Didn't got any luck finding an answer on google , so this is my last try before trying other methods.

I have a script like this:

        // 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");

            }

        }

to make it work , I chmod'ed the uploads directory and all it's files and dirs to 777 ( beter suggestion here? )

The long type evaluates to 'images' and this is a directory has already been created on the server.

Now , the script create the folder named with year with the permissions 341. This not wat I want because it terminates the recursive folder buildup or blocks it's content from me.

Any help or suggestions?

php version : 5.2.5

configure command : './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' '--with-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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泪眸﹌ 2024-10-01 22:48:38

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

Don't use the string "0777", use 0777.

老旧海报 2024-10-01 22:48:38

正如 Alex 所提到的,您应该输入八进制值而不是字符串,出于安全原因从不授予文件夹完全权限,请使用 0755 代替。

As mentioned by Alex, you suppose to enter OCTAL value not a STRING also, for security reasons never give full permission to folders use 0755 instead.

冰葑 2024-10-01 22:48:38

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

The real permissions depend on the parameter to mkdir and the umask. The umask is subtracted from the permissions given to mkdir. Try setting your umask to 0 before doing the mkdir.

栀子花开つ 2024-10-01 22:48:38

我也刚刚遇到这个问题,尽管 mkdir 设置为 0755,但 PHP 将权限设置为 1314。此问题是所创建的文件夹位于具有权限 0700 的父文件夹下。当我将 mkdir 的权限更改为 0700 时,它创建了具有正确权限的文件夹。因此,看起来(从逻辑上讲)您无法授予子文件夹比其父文件夹更大的权限。

在您的情况下,父文件夹可能设置为 0755 并且您尝试使用 0777 创建子文件夹。

I have also just encountered this issue where PHP sets the permissions to 1314, despite mkdir being set to 0755. This issue was that the folders that were being created were under a parent folder with the permissions 0700. When I changed the permissions with mkdir to 0700 it created the folders with the correct permissions. So it seems (quite logically) you cannot permission a child folder with greater permissions than it's parent.

In your case, a parent folder was probably set to 0755 and you were attempting to create a child with 0777.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文