PHP解压缩本地文件


PHP Unzip Local File

嗨,我需要使用ftp下载一个zip文件,然后在本地计算机上解压缩。我可以使用ftp_get下载该文件,但我需要帮助将其解压缩到特定位置。

        $ftpServer = "server";
        $ftpUser = "user";
        $ftpPassword = "password";
        $ftp_server = $ftpServer;
        $ftp_conn = ftp_connect($ftp_server);
        $ftp_login = ftp_login($ftp_conn, $ftpUser, $ftpPassword ); 
        if(!$ftp_conn) 
            die("A connection to $ftpServer couldn't be established"); 
        else if(!$ftp_login) 
            die("Your login credentials were rejected"); 
        else
        {
            $file = "C:/files/downloads/FILE_NAME.ZIP";
            $server_file = "/FILE_NAME.ZIP"; 
            if (ftp_get($ftp_conn, $file, $server_file, FTP_ASCII)) 
            {
                $zip = new ZipArchive;
                $res = $zip->open($file);
                if ($res === TRUE) 
                {
                  $zip->extractTo('C:/files/Feeds/');
                  $zip->close();
                }
                unlink($file);
            }
            else 
            {
                echo "There was a problem'n";
                $this->index();
            }
        }

谢谢你的帮助。

尝试使用此代码

解压缩php:-

<?php
$zip = new ZipArchive;
if ($zip->open('/sites/gallery.zip') === TRUE) {
    $zip->extractTo('/sites/New folder/test');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

如需参考,请参阅此链接文档

您可以将ZipArchive类用于此

$archive = new ZipArchive;
if ($archive->open('my_zip_fil.zip') === TRUE) {
    $archive->extractTo('destination/dir');
    $archive->close();
}

ZipArchive文档