dongxiansi0158 2019-05-22 07:23
浏览 159

为什么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?

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥20 Python安装cvxpy库出问题
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥15 python天天向上类似问题,但没有清零
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 C#调用python代码(python带有库)
    • ¥15 活动选择题。最多可以参加几个项目?
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题