嗨我需要使用ftp下載zip文件,然後在本地計算機上解壓縮。我可以使用ftp_get下載文件,但我需要將它解壓到特定位置。PHP解壓縮本地文件
$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的[ZipArchive](http://www.php.net/manual/en/class.ziparchive.php)嗎? –
是的,我做了,但有些理由,它不適合我。 – user4676307
如果你展示了一些你的代碼,那麼它可能會有幫助,所以我們可以看看你在做什麼,並試圖找出你做錯了什麼.....如果你不顯示你的代碼,我們所有可以做的是做野蠻的猜測,這浪費了我們的時間,並沒有幫助你 –