简体   繁体   English

使用php脚本提取zip文件

[英]Extract the zip file using php script

I have a zip file and i used the following code to extract that zip and put all extracted file in another location. 我有一个zip文件,我使用以下代码提取了该zip文件并将所有提取的文件放在另一个位置。

$zip = new ZipArchive;
echo $zip;
if ($zip->open("$pwd/wordpress-3.4.2.zip") === TRUE) {
    $zip->extractTo("$pwd/Repo/");
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}

But i cant any extracted file whether it show 'ok' in browser. 但是我无法提取任何文件,无论它在浏览器中显示“确定”。 What is the mistake in the code i cant found. 我找不到的代码有什么错误。 another thing to download the zip file from the "http://wordpress.org/latest.zip" site. 从“ http://wordpress.org/latest.zip”站点下载zip文件的另一件事。 i used the code written bellow. 我用下面写的代码。 Here also i cant download the file. 在这里我也无法下载文件。

$foo = system('wget http://www.myserver.com/file.txt ~',$output);

It appears that the ZipArchive needs a reference to the library containing that class. 似乎ZipArchive需要引用包含该类的库。

Also make sure that in your php.ini file, you have enabled the library that enables zip files functions to work on your server. 还要确保在您的php.ini文件中,启用了启用zip文件功能的库以在您的服务器上工作。 (The zip extension is loaded by default under PHP 5.3) (默认情况下,PHP 5.3加载了zip扩展名)

Again, make sure the directory you want to extract the files has write permissions. 再次,确保要提取文件的目录具有写权限。

You could also use: 您还可以使用:

exec('wget http://wordpress.org/latest.zip -O temp.zip');
exec('unzip temp.zip -d /somedir');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM