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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮