PHP uses ziparchive hints fatal Error:class ziparchive not found in solution _php tips

Source: Internet
Author: User

This example describes a workaround for PHP using the ziparchive hint fatal error:class ziparchive not found in. Share to everyone for your reference. Specifically as follows:

Ziparchive is a compression and decompression function that comes with PHP, and it's a matter of course today when you use the new ziparchive to create a zip file, you get a hint fatal error:class ziparchive not found in error, Interested friends together to see how to solve.

The test code is as follows:

Copy Code code as follows:
PHP uncompressed file (Zip)
function Unzip_file ($file, $destination) {
$zip = new Ziparchive ();
Open compressed 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");

Discovery during execution
Fatal error:class ' ziparchive ' not found in e:wwwqqdown.php to line 63
see this is not undefined, so small series Baidu search, the following explanation

The solution under Windows is:

1, in the php.ini file, will extension=php_zip.dll before the semicolon ";" Removal
Reboot the Apache server, and we'll try again to find out.

Add:

If it is a Linux system refer to the following method

There's no php_zip.dll this file under Linux.
You need to recompile PHP's Zip module. The specific installation method is as follows:

Copy Code code 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

It is possible to use the root permission when the make install command is last used, so sudo is recommended for running. After installation, the screen prompts for the location of the zip.so. Then record it, such as:/usr/local/lib/php/extensions/zip.so.

2, the use of root permissions to modify the php.ini (usually in the/usr/local/lib/folder, but depending on the original installation of PHP, you can through the phpinfo () to view):
Add extension =/usr/local/lib/php/extensions/zip.so, then also in php.ini file, change zlib.output_compression = off to Zlib.output_ compression = on;

3, in the end don't forget to restart Apache:apachectl restart;

Note: There are some friends on the website that say zlib.output_compression = off change to zlib.output_compression = on; I don't have any operations under windows that I don't see in the php.ini file, but it does make or extract files.

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.