ZipArchive: class not found |
Hello,
I can't use the ZipArchive class in CI 4.0.0-rc.3, I can't find out a solution... Thanks in advance for your support! ![]()
There is no ZipArchive in CI4, nor in CI3.
You are trying to open \ZipArchive, but the error message shows it can't find app\Controllers\Back\ZipArchive, which doesn't feel right. Could this be a namespace problem?
I just want to use the PHP ZipArchive class (https://www.php.net/manual/en/class.ziparchive.php).
I got the same problem when removing the backslash : $zip = new ZipArchive(); I can't manage to use it with CI4, I got no problem with CI3. Any idea?
The problem is that the second reference to the ZipArchive class doesn’t have a prefix slash, so PHP thinks it is relative to the current namespace.
CI4 is awesome because you can use almost any library with it !
For working with ZIP Files I recommend this one: https://github.com/Ne-Lexa/php-zip It is AWESOME and has some great features ! It is very simple to make it work with CI4. Easier with composer ! Please tell me if you need help installing it. Here is a example how to use the library: PHP Code: $projectName = 'Project'; This code will ZIP a entire folder, including sub-directories, set comments for the ZIP file, set a password and output it to browser without saving the file in server ! Awesome right ?
CI4 using php namespace, may be this affect for call class ZipArchive from Controller. I have solved this problem by way:
- Create helper, ex: zip_helper (file store in folder App/Helpers/) and define function ex: zipFile($fileAddPath, $fileZipPath): PHP Code: function zipFile($filePath) - Load helper in controller: PHP Code: helper("zip");
For me using
Code: $zip = new ZipArchive; or Code: $zip = new \ZipArchive; in controller method did not work, untill I added Code: use ZipArchive; at the top of the controller. Then it started to work ![]()
==
Donatas G. |
Welcome Guest, Not a member yet? Register Sign In |