简体   繁体   English

在PHP中提取ZIP,覆盖所有内容

[英]Extract ZIP in php, overwriting everything

I'm extracting server side .zip using this: 我正在使用以下方法提取服务器端.zip:

<?php
$unzip = shell_exec("unzip zipp1.zip");
?>

It's working fine, but it doesn't overwrite existing files (and I need it!). 它工作正常,但不会覆盖现有文件(我需要它!)。

Everything is in the same folder, chmod 777. 一切都在同一个文件夹chmod 777中。

Can I add something to fix? 我可以添加一些要修复的东西吗? Tnx! 天哪!

If you really need to use shell, you can write unzip -o zipp1.zip . 如果确实需要使用shell,则可以编写unzip -o zipp1.zip

However, PHP has a library for working with Zip archives, called ZipArchive : http://php.net/manual/en/class.ziparchive.php 但是,PHP有一个用于处理Zip存档的库,称为ZipArchivehttp : //php.net/manual/zh/class.ziparchive.php

There you can extractTo which overwrites by default: http://php.net/manual/en/ziparchive.extractto.php 在那里,您可以extractTo默认情况下覆盖的extractTohttp : //php.net/manual/en/ziparchive.extractto.php

It's usually a good security practice to disable shell_exec() , so using PHP's libraries is recommended. 禁用shell_exec()通常是一个很好的安全实践,因此建议使用PHP的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM