开发者

How do I set the permissions of the files I extract with ezcArchive - ezComponents

开发者 https://www.devze.com 2023-01-18 05:48 出处:网络
I am using the 开发者_运维问答ezcomponents archive component to extract uploaded files that is being uploaded to my website. The extracting part is very easy but how do I specifically assign the right

I am using the 开发者_运维问答ezcomponents archive component to extract uploaded files that is being uploaded to my website. The extracting part is very easy but how do I specifically assign the right permissions to those files being extracted?

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();

}

Regards


You can use a callback for every extracted file/directory, in order to set the desired permissions. You specify the callback through the ezcArchiveOptions.


Do a recursive chmod on the directory. (Use this, if you don't find a built in functionality in 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;
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号