Search code examples
phpunzipphp-ziparchivefile-ownership

Unzipped files change owner, php


I have a zip file into a directory like this:

drwxr-xr-x 2 salome  salome  4096 Dec 16 17:41 staff.zip

When I unzip the file with ZipArchive class, all the upzipped files are owner by nobody user. Is there a way to avoid this owner change?

  1. I am able to use ftp if it is required (only as salome user).
  2. This script eventually will be shared at multiple hosts, so the idea is keep it as generic as possible.

Solution

  • You might consider extending the zipArchive class and override the extractTo method to also perform a chown() on the files in the directory.

    Based on the use case you discussed in the comments, you also might want to consider the use of the Phar archive format. php.net/manual/en/intro.phar.php

    Phar's would allow your module submitters to submit a file file of executable PHP code that you would not need to extract at all.