使用php解压缩压缩文件

时间:2014-08-21 11:06:50

标签: php ftp zip unzip zipfile

让我们先看看我想要完成的事情。

我在网络办公室工作,我们在每个网站都使用几乎相同的CMS。 CMS包含超过6000个文件,因此上传需要很长时间。上传压缩文件然后在FTP服务器上解压缩它会快得多。

我浏览了stackoverflow,找到了这个帖子:Unzip a file with php

这很好。但是,当我使用此代码时:

<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'concrete5.6.3.1-Dansk.zip';

// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);

$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
  // extract it to the path we determined above
  $zip->extractTo($path);
  $zip->close();
  echo "WOOT! $file extracted to $path";
} else {
  echo "Doh! I couldn't open $file";
}
?>

我遇到以下问题:

解压缩整个.zip文件。这包括最初压缩的文件夹。这将创建我的index.php文件,一个目录太深。

所以不是这样的:     的 www.hello.com/index.php

它会出现:     的 www.hello.com/folder/index.php

那是问题#1。

问题#2:

我在mac上工作,当我解压缩我的压缩文件时,我得到了烦人的&#34; _macosx&#34;文件夹也是。

有没有办法解决这两个问题? :)

1 个答案:

答案 0 :(得分:0)

我正在使用的非常简单的方法

system('unzip assets_04_02_2015.zip');