Guest User

Untitled

a guest
Jun 3rd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. function getContent($action){
  2.         global $smarty;
  3.         global $config;
  4.  
  5.  
  6.         //1 . List all files from directory of the action
  7.         $dir    = 'partner_file_uploads/'.$action;
  8.  
  9.         var_dump($dir);
  10.        
  11.         $files_to_zip = scandir($dir);
  12.        
  13.  
  14.         Zip($dir, './testzipje.zip');
  15.         //$result = create_zip($files_to_zip,'tesssst01.zip');
  16.  
  17.     }
  18.  
  19.     function Zip($source, $destination)
  20.     {
  21.         if (!extension_loaded('zip') || !file_exists($source)) {
  22.             return false;
  23.         }
  24.  
  25.         $zip = new ZipArchive();
  26.         if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
  27.             return false;
  28.         }
  29.  
  30.         $source = str_replace('\\', '/', realpath($source));
  31.  
  32.         if (is_dir($source) === true)
  33.         {
  34.             $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
  35.  
  36.             foreach ($files as $file)
  37.             {
  38.                 $file = str_replace('\\', '/', $file);
  39.  
  40.                 // Ignore "." and ".." folders
  41.                 if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
  42.                     continue;
  43.  
  44.                 $file = realpath($file);
  45.  
  46.                 if (is_dir($file) === true)
  47.                 {
  48.                     $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
  49.                 }
  50.                 else if (is_file($file) === true)
  51.                 {
  52.                     $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
  53.                 }
  54.             }
  55.         }
  56.         else if (is_file($source) === true)
  57.         {
  58.             $zip->addFromString(basename($source), file_get_contents($source));
  59.         }
  60.         header("Content-Type: archive/zip"); // works with "application/zip" too
  61.         header("Content-Disposition: attachment; filename='my-archive.zip");
  62.         return $zip->close();
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment