Home  >  Article  >  Backend Development  >  Bug_PHP tutorial on the read_dir method in the Zip coding class of the Codeigniter framework

Bug_PHP tutorial on the read_dir method in the Zip coding class of the Codeigniter framework

WBOY
WBOYOriginal
2016-07-21 14:58:19851browse

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

http://www.bkjia.com/PHPjc/363823.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363823.htmlTechArticleCodeigniter framework’s compression decoding class, the read_dir method allows you to compress a folder that exists somewhere on the server ( and the files and subfolders within it). Provide a...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn