如何通过ZipArchive解压缩归档文件

时间:2015-10-02 19:22:44

标签: php ziparchive

到目前为止,在查看了如何解压缩文件的多个示例后,我对我现在缺少的内容感到有些困惑。

我使用WordPress和AdvancedCustomFields来指定我要上传的文件类型。我需要解压缩这个文件并找出内部文件,将其作为源文件使用。

} else if(get_sub_field('media_type') == 'Zip'){
        /* Get Path Name */
        $file = get_sub_field('file');
        $pieces = explode("/", $file);
        $lastZip =  end($pieces);
        array_pop($pieces ); //removes last
        $path = implode("/", $pieces);
        $path = $path."/";
        /* Get Name of File and concat .png */
        $last = explode(".", $lastZip);
        $last = $last[0].".png";
        /* Append new filename to proper pathing */
        $pathFile = $path.$last;

        $zip = new ZipArchive;

        $zip->open($lastZip, ZipArchive::CREATE);
        print_r($zip);
        if ($zip === TRUE) {
            $zip->extractTo($path);
            $zip->close();
            echo 'File extracted to: $path';
        } else {
            echo "does not work!";
        }


      ?><span><img src="<?php echo $pathFile; ?>" /></span>
    <?php
    }

print_r($zip)的结果是:

ZipArchive Object (
    [status] => 0 
    [statusSys] => 0 
    [numFiles] => 0 
    [filename] => /var/www/vhosts/domain.com/httpdocs/example.zip 
    [comment] => 
)

0 个答案:

没有答案