| 状态 | 草稿 |
|---|---|
| Todo | Needs updating from library to module |
| 官方最后更新时间 | 2008/08/27 08:17 |
Archive 扩展是一种很方便给文件进行动态打包( Zip/Tar 格式等等)。它不仅可以保持原有的文件系统,还可以它打包后的文件发送给用户或下载,但不能保存在服务器端。
当前它支持 Zip,GZip,BZip 和 Tar 压缩打包。
使用之前必须在 application/config/config.php 文件中配置:
$config['modules'] => array ( 'modules/auth', 'modules/archive' )
然后你就可以实例化扩展来用。例如:
$this->archive = new Archive;
四种可用驱动:Zip,GZip,BZip 和 Tar。默认是 Zip 如果想选择其他格式需要传递相应的格式:
// 加载 GZip 驱动 $this->archive = new Archive('gzip');
add($path, $name = NULL, $recursive = NULL) 添加文件或目录到 archive 中。其参数:
$path 要添加文件或目录的路径。相对路径必须是相对的网站的根目录。$name 为打包文件或目录制定的名称$recursive add files recursively, used with directories - default FALSE添加 file.txt 文件到 archive:
$this->archive->add("files/uploads/file.txt");
save($filename) 保存创建的打包文件到硬盘。
$filename 打包文件要保存的路径。相对路径必须是相对的网站的根目录。$this->archive->save("myarchive.zip");
download($filename) 提供打包下载。
$filename 打包文件的名称$this->archive->download("myarchive.zip");