Home  >  Article  >  php教程  >  PHP压缩文件夹的具体实现方法

PHP压缩文件夹的具体实现方法

WBOY
WBOYOriginal
2016-06-13 11:09:321202browse

不过zlib 库中没有对文件夹操作的函数(当然,我们也可以自己写一个,但这样太麻烦),我们可以去网上下载一些现成的,由先辈们写的,扩展了 zlib 函数库的工具。

PHP压缩文件夹的具体实现代码:

  1.  ?php  
  2. require_once("archive.php");  
  3. $test = new zip_file("app.zip");  
  4. $test->set_options(  
  5. array(  
  6. ‘basedir’ => dirname($modpath),  
  7. ‘inmemory’ => 0, //不在内存压缩.
    而是直接存放到磁盘.如果要压缩下载,则可以选择为1  
  8. ‘recurse’ => 1, //是否压缩子目录,
    resurse,递归的意思?  
  9. ’storepaths’ => 1, //是否存储目录结构,我选是。  
  10. ‘overwrite’ => 1, //是否覆盖  
  11. ‘prepend’ => "", //未知  
  12. ‘followlinks’ => 0, //未知  
  13. ‘method’ => 1, //未知  
  14. ’sfx’ => "", //不知道什么意思  
  15. )  
  16. );  
  17. $test->add_files("src/archive.php");  
  18. $test->add_files("/App");  
  19. $test->create_archive();  
  20. $test->download_file();
    //不写这一行,数据只存在内存里  
  21. //以下代码为解压  
  22. $test = new tar_file("archives/test.tar");  
  23. $test->set_options(array(’inmemory’ => 0));  
  24. $test->extract_files();  
  25. ?> 

希望通过本文介绍的这段代码示例可以帮助我们进一步了解PHP压缩文件夹的含义。


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