【问题标题】:Unzip a zipped file using php使用 php 解压缩压缩文件
【发布时间】:2014-08-21 11:06:50
【问题描述】:

让我们先看看我想要完成什么。

我在一家网络局工作,我们为每个网站使用几乎相同的 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 上工作,当我解压缩我的压缩文件时,我也会得到烦人的“_macosx”文件夹。

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

【问题讨论】:

    标签: php ftp zip unzip zipfile


    【解决方案1】:

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

    system('unzip assets_04_02_2015.zip'); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 2010-09-05
      相关资源
      最近更新 更多