0

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

Gordon
  • 312,688
  • 75
  • 539
  • 559
Etienne Marais
  • 1,660
  • 1
  • 22
  • 40

2 Answers2

1

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

tobyS
  • 860
  • 1
  • 7
  • 15
0

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;
}
?>
Stewie
  • 3,103
  • 2
  • 24
  • 22