php创建具有341权限的文件夹
在谷歌上没有找到答案,所以这是我在尝试其他方法之前的最后一次尝试。
我有一个这样的脚本:
// 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要使用字符串“0777”,而使用 0777。
Don't use the string "0777", use 0777.
正如 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.
真正的权限取决于 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.
我也刚刚遇到这个问题,尽管
mkdir
设置为0755
,但 PHP 将权限设置为1314
。此问题是所创建的文件夹位于具有权限0700
的父文件夹下。当我将mkdir
的权限更改为0700
时,它创建了具有正确权限的文件夹。因此,看起来(从逻辑上讲)您无法授予子文件夹比其父文件夹更大的权限。在您的情况下,父文件夹可能设置为
0755
并且您尝试使用0777
创建子文件夹。I have also just encountered this issue where PHP sets the permissions to
1314
, despitemkdir
being set to0755
. This issue was that the folders that were being created were under a parent folder with the permissions0700
. When I changed the permissions withmkdir
to0700
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 with0777
.