解压缩远程服务器上的文件

时间:2017-03-17 15:11:05

标签: php ziparchive

如标题中所述,我试图在远程服务器中解压缩文件,这是我的功能:

    private function unzip(){
        $ZIP_ERROR = [
            \ZipArchive::ER_EXISTS => 'File already exists.',
            \ZipArchive::ER_INCONS => 'Zip archive inconsistent.',
            \ZipArchive::ER_INVAL => 'Invalid argument.',
            \ZipArchive::ER_MEMORY => 'Malloc failure.',
            \ZipArchive::ER_NOENT => 'No such file.',
            \ZipArchive::ER_NOZIP => 'Not a zip archive.',
            \ZipArchive::ER_OPEN => "Can't open file.",
            \ZipArchive::ER_READ => 'Read error.',
            \ZipArchive::ER_SEEK => 'Seek error.',
        ];

        $zip = new \ZipArchive();
        $newFile = 'tmp_file.zip';
        $file = "app.zip";
        $url = "http://my-url.com/files/";
        $arrContextOptions=array(
            "ssl"=>array(
                "verify_peer"=>false,
                "verify_peer_name"=>false,
            ),
        );
        file_put_contents($newFile, file_get_contents($url.$file, false, stream_context_create($arrContextOptions)));
        $open = $zip->open($newFile);

        if ($open === TRUE){
            $zip->extractTo($url);
            $zip->close();
            var_dump('success unzipping');
        } else {
            $msg = isset($ZIP_ERROR[$open])? $ZIP_ERROR[$open] : 'Unknown error.';
            var_dump($msg);
        }

    }

但我收到此错误:Not a zip archive.虽然它的zip文件肯定 我在这里缺少什么?

0 个答案:

没有答案