Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getContent($action){
- global $smarty;
- global $config;
- //1 . List all files from directory of the action
- $dir = 'partner_file_uploads/'.$action;
- var_dump($dir);
- $files_to_zip = scandir($dir);
- Zip($dir, './testzipje.zip');
- //$result = create_zip($files_to_zip,'tesssst01.zip');
- }
- function Zip($source, $destination)
- {
- if (!extension_loaded('zip') || !file_exists($source)) {
- return false;
- }
- $zip = new ZipArchive();
- if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
- return false;
- }
- $source = str_replace('\\', '/', realpath($source));
- if (is_dir($source) === true)
- {
- $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
- foreach ($files as $file)
- {
- $file = str_replace('\\', '/', $file);
- // Ignore "." and ".." folders
- if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
- continue;
- $file = realpath($file);
- if (is_dir($file) === true)
- {
- $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
- }
- else if (is_file($file) === true)
- {
- $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
- }
- }
- }
- else if (is_file($source) === true)
- {
- $zip->addFromString(basename($source), file_get_contents($source));
- }
- header("Content-Type: archive/zip"); // works with "application/zip" too
- header("Content-Disposition: attachment; filename='my-archive.zip");
- return $zip->close();
- }
Advertisement
Add Comment
Please, Sign In to add comment