0

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

我有一个这样的脚本:

        // 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' '--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'--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'--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'--with-ttf' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with- zlib-dir=/usr'--with-ttf' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with- zlib-dir=/usr'

4

3 回答 3

3

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

于 2010-09-24T14:25:11.153 回答
1

正如亚历克斯所提到的,您还假设输入八进制值而不是字符串,出于安全原因,永远不要给文件夹使用0755的完全权限。

于 2010-09-24T14:31:04.763 回答
0

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

于 2010-09-24T14:21:29.210 回答