Created
March 24, 2011 17:16
-
-
Save nickdunn/885455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('pclzip.lib.php'); | |
$name = 'publishfiltering'; | |
$tmp_zip_path = $name . '-' . sha1(microtime()); | |
$tmp_zip_name = $tmp_zip_path . '.zip'; | |
file_put_contents($tmp_zip_name, file_get_contents('https://github.com/nickdunn/publishfiltering/zipball/1.6.0')); | |
$tmp_zip = new PclZip($tmp_zip_name); | |
$tmp_zip->extract(PCLZIP_OPT_PATH, $tmp_zip_path); | |
$contents = $tmp_zip->listContent(); | |
if(is_array($contents)) { | |
$folder = $contents[0]['filename']; | |
$new_zip_path = $name; | |
$new_zip_name = $name . '.zip'; | |
$new_zip = new PclZip($new_zip_name); | |
$new = $new_zip->create($tmp_zip_path . '/' . $folder . '/', PCLZIP_OPT_REMOVE_PATH, $tmp_zip_path . '/' . $folder); | |
header('Content-type: application/zip'); | |
header('Content-Disposition: attachment; filename="' . $name . '"'); | |
readfile($new_zip_name); | |
rrmdir($tmp_zip_path); | |
unlink($tmp_zip_name); | |
unlink($new_zip_name); | |
exit; | |
} else { | |
die('Zip is empty'); | |
} | |
// recursively delete directories | |
// http://php.net/manual/en/function.rmdir.php | |
function rrmdir($dir) { | |
if (is_dir($dir)) { | |
$objects = scandir($dir); | |
foreach ($objects as $object) { | |
if ($object != "." && $object != "..") { | |
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); | |
} | |
} | |
reset($objects); | |
rmdir($dir); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment