1

PHP ZipArchive chmod 600 the problem of access to the file.

A temporary archive is created, with rights 600 (-rw-------) because of which it can not work with it.

Here's what the temporary archive looks like: archive_19-05-2020_18-33-51.zip.GIKCH2

Locally, everything is archived and the tempo file I do not even see in the process. When transferring to the server (linux), there is a problem with access to the archive.

Archiving Code Standard.

$zip = new \ZipArchive();
if ($zip->open('upload/archive_19-05-2020_18-33-51.zip', \ZipArchive::CREATE) !== TRUE) {
    throw new \Exception('Cannot create a zip file');
}
$zip->addFile('upload/file.txt', 'file.txt'); 
$zip->close();

When generating other files of the same csv, the file gets 644 permissions and you can safely work with it.

I can’t understand what the problem is, why the archive is created with limited rights, although locally on (windows) everything works without problems.

Ортем
  • 21
  • 4
  • maybe this helps: https://www.php.net/manual/en/function.chmod.php – Random Name May 19 '20 at 17:58
  • This will not work. Each time a new file name is generated, characters are added after the extension. [zip.GIKCH2] – Ортем May 19 '20 at 18:03
  • Permissions in Windows are different from those in Unix-like operating systems. How do you create/upload the temporary file and what are the users/groups involved? – Álvaro González May 19 '20 at 18:04
  • In the same script, I generate a csv file that gets 644 permissions. Files are created on behalf of Apache – Ортем May 19 '20 at 18:28
  • Now I found out through experiments. The problem is one of two, either because the php version is low (5.4) on the server you are using, or the configuration of the web server itself does not allow it. It remains to find out what exactly is the problem – Ортем May 19 '20 at 18:28
  • [This question](https://stackoverflow.com/questions/428416/setting-the-umask-of-the-apache-user) is old but basic concepts should be still correct. – Álvaro González May 20 '20 at 10:47

1 Answers1

1

The problem was that the php version is low (5.4) on the server i using. I upgraded php version for 5.6 and problem resolved. Thanks you all.

Ортем
  • 21
  • 4