Php 如何解压缩文件夹并删除压缩的原始文件?

Php 如何解压缩文件夹并删除压缩的原始文件?,php,zip,unzip,delete-file,rights-management,Php,Zip,Unzip,Delete File,Rights Management,我正在为我的CMS创建类似easy installer\setupper的东西。当用户使用我的CMS下载.zip并将其解压到php服务器上的某个文件夹中时,他会看到一个文件-install.php和一个名为-Contents.zip的zip文件夹。我需要一些php函数从该Contents.zip文件中提取文件,然后删除该文件。(如果可能的话,我希望在文件夹解压缩后立即为从中提取的文件\文件夹授予不同的权限) 怎么做这样的事 你可以用它来达到你的目的 此外,您可能会发现一个有用的方法 <?p

我正在为我的CMS创建类似easy installer\setupper的东西。当用户使用我的CMS下载.zip并将其解压到php服务器上的某个文件夹中时,他会看到一个文件-install.php和一个名为-Contents.zip的zip文件夹。我需要一些php函数从该Contents.zip文件中提取文件,然后删除该文件。(如果可能的话,我希望在文件夹解压缩后立即为从中提取的文件\文件夹授予不同的权限)

怎么做这样的事

你可以用它来达到你的目的

此外,您可能会发现一个有用的方法

<?php

$zip = new ZipArchive();
$filename = "./test112.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>
要删除您可以使用的文件

比如说,

unlink('test.html');
unlink('testdir');

我强烈建议yuo阅读官方PHP文档。

这是官方PHP 5.2 defalt apache PHP中的“PHP ZipArchive库”吗?从哪里删除该zip文件?@Ole是的,ZipArchive随官方发行版一起提供;但是,它有一个外部依赖,所以当有人从某个提供商处购买Apache Web主机时,他可能无法使用此功能?
unlink('test.html');
unlink('testdir');