为什么PHP 5.6或更高版本的ZipArchive总是将文件权限设置为0666而不是0644?

I found that PHP script generated zip files cannot be restored for execution if the compression was done using PHP 5.6 to PHP 7.3. Zip file restoration / decompression, to run PHP scripts, only works if the PHP scripts were zipped under PHP 5.5.

While testing, using ZipArchive function, I found that, with PHP 5.5 all file permissions are set to 0644. It does not matter whether the original file permissions were set to 0666 or 0444 or any other value. When you unzip the file the the permissions will be set to 0644.

I then tested this with PHP 5.6 and tried to zip and unzip files whose permissions were 0644 or 0444. When unzipped their permissions where set to 0666.

PHP programs zipped up with PHP versions 5.6 to 7.3 would not work when unzipped on my and other servers unless I manually changed all file permissions to 0644 and all directory permissions to 0755. Where as higher versions of PHP, 5.6 to 7.3, set file permissions to 0666 which stops them from being executed - the unzipped php files will not run. I have written more about this at http://drpetersnews.com/php-zip-archive-not-working-apache-server-hard-disk-full-problems.php and have reported this to PHP developers at https://bugs.php.net/bug.php?id=69536.

Actually, ZipArchive can work correctly if we, as the PHP script developer, use the ZipArchive function to set the file and directory permissions. For example with additions to PHP statements:

$zipArchive->addFile('atestzip.php', 'atestzip.php', 0644);

$zipArchive->addEmptyDir ( string $dirname, 0755 );

There could be a way to create default settings for directory and file permissions:-

$zipArchive->setpermissions ( 0755, 0644 ); 

I love using ZipArchive functions and have a lot of PHP code that generates zip files. And it is very easy to use Windows Explorer to search the contents of zip files when I am trying to find something in my zip files. Furthermore, I release a lot of PHP code in zipped up files but unfortunately I am unable to migrate to PHP 5.6 or higher because ZipArchive does not work properly on the higher versions of PHP. Therefore, I am now stuck with PHP 5.5.

I still believe zipped files are a wonderful product and very easy to use and distribute.

Can you guys help me get the PHP developers upgrade PHP so that all versions of PHP from 5.6 to 7.3 will zip files with the correct permissions?

donglian4464
donglian4464 (stackoverflow.com早些时候崩溃了,我无法弄清楚如何将php代码放在评论中,因为它说它太长了。)在PHP5.6下压缩的文件权限将设置为0666而不是0644.这些是压缩的在PHP5.5下,当在PHP5.6下解压缩时,将文件权限设置为0644.尝试这个直到PHP版本7.3。我希望这可以解释我的问题。谢谢。
一年多之前 回复
douzhi1972
douzhi1972 我已在InMotion和Siteground服务器上测试了此代码。两者都给出相同的结果。您可以在服务器上将PHP设置为5.5版,并将一些php脚本压缩为files55.zip,然后再次尝试将其恢复并检查权限。然后将您的PHP版本设置为5.6并尝试使用不同的文件名压缩文件,例如files56.zip然后恢复它们并检查文件权限。然后尝试在PHP5.6下解压缩files55.zip并在P​​HP5.5下解压缩files56.zip。
一年多之前 回复
douya2433
douya2433 嗨@Progrock。<br/>由于这是我第一次尝试添加评论并且表现不符合我的预期,因此难以发布回复。我用过的代码可以在这里添加。请从<br/><br/>drpeterscode.com/tmpso/phpzipping.txt下载
一年多之前 回复
doutang1992
doutang1992 这很有意思,但要成为SO的主题,您需要一个明确定义的问题。说明您所做的事情,您的期望以及您在问题中列出的代码的实际结果。或者更确切地说,制作一个可重现的问题,我们可能会尝试修复或找到变通方法。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐