php zip compression code

WBOY
Release: 2016-07-25 08:43:22
Original
970 people have browsed it
  1. $error = ""; //error holder
  2. if(isset($_POST['createpdf'])){
  3. $post = $_POST;
  4. $file_folder = "files/"; // folder to load files
  5. if(extension_loaded('zip')){ // Checking ZIP extension is available
  6. if(isset($post['files']) and count($post['files']) > 0){ // Checking files are selected
  7. $zip = new ZipArchive(); // Load zip library
  8. $zip_name = time().".zip"; // Zip name
  9. if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){ // Opening zip file to load files
  10. $error .= "* Sorry ZIP creation failed at this time
    ";
  11. }
  12. foreach($post['files'] as $file){
  13. $zip->addFile($file_folder.$file); // Adding files into zip
  14. }
  15. $zip->close();
  16. if(file_exists($zip_name)){
  17. // push to download the zip
  18. header('Content-type: application/zip');
  19. header('Content-Disposition: attachment; filename="'.$zip_name.'"');
  20. readfile($zip_name);
  21. // remove zip file is exists in temp path
  22. unlink($zip_name);
  23. }
  24. }else
  25. $error .= "* Please select file to zip
    ";
  26. }else
  27. $error .= "* You dont have ZIP extension
    ";
  28. }
  29. ?>
  30. Download As Zip
  31. Create Zip

  32. * File Type File Name
    flowers.jpg
    fun.jpg
    uvamsi.docx
    abc.pdf
  33.  
复制代码

php, zip


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template