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

时间:2010-09-24 14:16:01

标签: php permissions chmod mkdir

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

我有一个这样的脚本:

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

            }

        }

为了使它工作,我chmod'ed上传目录及其所有文件和dirs到777(在这里提出建议?)

long类型评估为'images',这是已在服务器上创建的目录。

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

任何帮助或建议?

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'

3 个答案:

答案 0 :(得分:2)

请勿使用字符串“0777”,请使用0777。

答案 1 :(得分:1)

正如亚历克斯所提到的,你想输入OCTAL值而不是STRING,出于安全考虑,从不给予文件夹完全权限使用 0755

答案 2 :(得分:0)

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