php的zip压缩代码

WBOY
WBOYasal
2016-07-25 08:43:22990semak imbas
  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
    php的zip压缩代码 flowers.jpg
    php的zip压缩代码 fun.jpg
    php的zip压缩代码 uvamsi.docx
    php的zip压缩代码 abc.pdf
  33.  
复制代码

php, zip


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn