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();
}
}
谢谢你的帮助。
您可以为此使用 ZipArchive class
$archive = new ZipArchive;
if ($archive->open('my_zip_fil.zip') === TRUE) {
$archive->extractTo('destination/dir');
$archive->close();
}
试试这个代码
Unzip.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';
}
?>
供您参考,请参阅此 link Documentation
您好,我需要使用 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();
}
}
谢谢你的帮助。
您可以为此使用 ZipArchive class
$archive = new ZipArchive;
if ($archive->open('my_zip_fil.zip') === TRUE) {
$archive->extractTo('destination/dir');
$archive->close();
}
试试这个代码
Unzip.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';
}
?>
供您参考,请参阅此 link Documentation