The codeigniter framework's compression decoding class, whose read_dir method allows you to compress a folder (and the files and subfolders in it) that exists somewhere on the server.
Provide a folder path and the zip class will recursively read it and recreate it to add to the archive. All files under the path you provide will be compressed, including all subfolders.
For example:
$path = '/path/to/your/directory/'; $this->zip->read_dir($path);
The default Zip file will save the complete folder path of the first parameter into the Zip file. If you want to ignore the folder structure before the target path, you can pass FALSE (boolean) to the second parameter.
For example:
$path = '/path/to/your/directory/'; $this->zip->read_dir($path, false);
This will create a ZIP file that includes “directory”, with all subfolders saved correctly inside, but does not include the folder /path/to/your.
The official document only mentions two parameters, but there are actually three set in the source code:
read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
Usually, within the framework running environment, there are several ways to obtain the path:
APPPATH – corresponds to the Codeigniter root directory, that is, application/
FCPATH – corresponds to the disk partition root directory, that is, <code><font face="NSimsun">D:xxxcodeigniter 根目录</font>
D:xxxcodeigniter root directory
When using methods such as FCPATH to obtain the absolute path of a directory, since the backslashes in the path are processed in the source code, the $root_path values before and after are inconsistent, and the second parameter false setting is invalid.
Reference material: http://codeigniter.org.cn/user_guide/libraries/zip.html