0

我正在使用 ezcomponents 存档组件来提取上传到我网站的上传文件。提取部分非常简单,但我如何专门为那些被提取的文件分配正确的权限?

http://ezcomponents.org/docs/tutorials/Archive#usage

$extract_dir = 'some existing directory';
$archive = ezcArchive::open($file, ezcArchive::ZIP);

while( $archive->valid() )
{
    if ( is_dir($extract_dir) === false )
    {
        @mkdir($extract_dir, 0777);
    }

    // Extract the current archive entry to /data/<issue_id>/
    $archive->extractCurrent($extract_dir);

    $archive->next();

}

问候

4

2 回答 2

1

您可以为每个提取的文件/目录使用回调,以设置所需的权限。您通过ezcArchiveOptions.

于 2011-02-23T08:03:52.203 回答
0

对目录执行递归 chmod。(如果您在 ezcomponents 中没有找到内置功能,请使用此功能)

<?php
function chmodr($path, $filemode) {
    if (!is_dir($path))
        return chmod($path, $filemode);

    $dh = opendir($path);
    while (($file = readdir($dh)) !== false) {
        if($file != '.' && $file != '..') {
            $fullpath = $path.'/'.$file;
            if(is_link($fullpath))
                return FALSE;
            elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode))
                    return FALSE;
            elseif(!chmodr($fullpath, $filemode))
                return FALSE;
        }
    }

    closedir($dh);

    if(chmod($path, $filemode))
        return TRUE;
    else
        return FALSE;
}
?>
于 2010-09-29T14:36:39.670 回答