使用兼容性更好的创建目录方式
当mkdir使用递归模式创建多层目录时,它的目录模式参数`mode`只会被设置在第一个目录上,为了保证兼容性,我们要手动设置所有创建的目录
This commit is contained in:
@@ -30,15 +30,28 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
*/
|
||||
private static function makeUploadDir($path)
|
||||
{
|
||||
if (!@mkdir($path, 0777, true)) {
|
||||
$path = preg_replace("/\\\+/", '/', $path);
|
||||
$current = rtrim($path, '/');
|
||||
$last = $current;
|
||||
|
||||
while (!is_dir($current) && false !== strpos($path, '/')) {
|
||||
$last = $current;
|
||||
$current = dirname($current);
|
||||
}
|
||||
|
||||
if ($last == $current) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!@mkdir($last)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$stat = @stat($path);
|
||||
$stat = @stat($last);
|
||||
$perms = $stat['mode'] & 0007777;
|
||||
@chmod($path, $perms);
|
||||
@chmod($last, $perms);
|
||||
|
||||
return true;
|
||||
return self::makeUploadDir($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user