unzipping while preserving permissions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    unzipping while preserving permissions

    Hi,

    I'm using PHP 4.4.4 with Apache 2 on Linux. I have a PHP function to
    unzip a file, but I would like the resulting unzipped file with all its
    sub-directories and files to have the same permissions as the parent
    file, or at least 755 perms. Right now, it is being created with
    rw-r--r-- perms. Here is my function

    function unzipFile($p_zi p_file_path, $p_zip_file_pwd ,
    $unzip_dir)
    {
    $cmd = "unzip ";
    if (!empty($p_zip_ file_pwd)) {
    $cmd .= " -P $p_zip_file_pwd ";
    } //
    $cmd .= " -o -d $unzip_dir $p_zip_file_pat h 2>&1";
    exec($cmd, $output, $return);
    // failed if non-zero
    if ($return != 0) {
    $output = join("<BR>\n", $output) . "<BR>\n";
    return $output;
    } // if
    return "";
    }

    Any suggestions on how to modify it? Thanks, - Dave

  • Andy Hassall

    #2
    Re: unzipping while preserving permissions

    On 21 Nov 2006 09:06:13 -0800, "laredotornado@ zipmail.com"
    <laredotornado@ zipmail.comwrot e:
    >I'm using PHP 4.4.4 with Apache 2 on Linux. I have a PHP function to
    >unzip a file, but I would like the resulting unzipped file with all its
    >sub-directories and files to have the same permissions as the parent
    >file, or at least 755 perms. Right now, it is being created with
    >rw-r--r-- perms. Here is my function
    >
    function unzipFile($p_zi p_file_path, $p_zip_file_pwd ,
    >$unzip_dir)
    {
    $cmd = "unzip ";
    if (!empty($p_zip_ file_pwd)) {
    $cmd .= " -P $p_zip_file_pwd ";
    } //
    $cmd .= " -o -d $unzip_dir $p_zip_file_pat h 2>&1";
    exec($cmd, $output, $return);
    // failed if non-zero
    if ($return != 0) {
    $output = join("<BR>\n", $output) . "<BR>\n";
    return $output;
    } // if
    return "";
    }
    >
    >Any suggestions on how to modify it? Thanks, - Dave
    What's your umask currently set to?

    Do the files have permissions in the original zip file? The "unzip" man page
    says:

    "
    Dates, times and permissions of stored directories are not restored
    except under Unix. (On Windows NT
    and successors, timestamps are now restored.)
    "

    ... which implies that the contents of the zip may influence the permissions.

    You could also reset the permissions after extraction, if umask isn't the key.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    Working...