php uses ZipArchive to prompt Fatal error: Class ZipArchive not found in solution

  • 2021-07-26 07:02:22
  • OfStack

This paper illustrates the solution of php using ZipArchive to prompt Fatal error: Class ZipArchive not found in. Share it for your reference. The details are as follows:

ZipArchive is a compression and decompression function of php. Today, when using new ZipArchive to create zip file, you will encounter an error prompting Fatal error: Class ZipArchive not found in. Interested friends will come to see the solution.

The test code is as follows:

//PHP Unzip the file ( zip ) 
function unzip_file($file, $destination){
$zip = new ZipArchive() ;
// Open zip file
if ($zip->open($file) !== TRUE) {
die ('Could not open archive');
}
// Create a file
$zip->extractTo($destination);
$zip->close();
echo ' Success ';
}
unzip_file("htdocs.zip","wenjianming");

Discover at execution time
Fatal error: Class 'ZipArchive' not found in E:wwwqqdown.php on line 63
See this is not undefined, so this site Baidu search 1, as follows

The solution under Windows is:

1. In the php. ini file, place the semicolon before extension=php_zip. dll ";" Removal;
Restart the Apache server, and we will try again to find out that it is ok

Additional:

If it is an linux system, refer to the following method

The file php_zip. dll is not available under Linux
Need to recompile the zip module of php under 1. The specific installation method is as follows:

cd /usr/src
wget http://pecl.php.net/get/zip
tar -zxvf zip
cd zip-1.x.x
phpize
./configure
make
sudo make install

Among them, root privileges may be required when the make install command is finally used, so it is recommended to use sudo to run. After installation, the location of zip. so will be prompted on the screen. Then record it as:/usr/local/lib/php/extensions/zip. so.

2. Modify php. ini with root permissions (usually under the/usr/local/lib/folder, but depending on the original installation of php, you can see it through phpinfo ()):
Add extension = /usr/local/lib/php/extensions/zip. so, and then in the same php. ini file, change zlib.output_compression = Off to zlib.output_compression = On;

3. Finally, don't forget to restart Apache: apachectl restart;

Note: Some friends about the website said that zlib.output_compression = Off should be changed to zlib.output_compression = On; I didn't do it under windows, and I didn't see it in the php. ini file, but it is possible to generate or extract files.

I hope this article is helpful to everyone's PHP programming.


Related articles: