Location: PHPKode > projects > @1 File Store > zipf.php
<?
if(isset($_GET["id"]) && $_GET["id"]!="") {
	$fileid=$_GET["id"];
} else {
	exit("Bad request");
 }
$MustLogin=1|2|4;
function rm($dir) {
if(!$dh = @opendir($dir)) return;
while (($obj = readdir($dh))) {
if($obj=='.' || $obj=='..') continue;
if (!@unlink($dir.'/'.$obj)) rm($dir.'/'.$obj);
   }
  @rmdir($dir);
}
require_once("libs/header.php");
$userlevel=$CurUser->getlevel();
$SQL="SELECT * FROM `".DB_PREFIX."file_list` WHERE `id`='".$fileid."'";
if(!$mysql->query($SQL))
{
 exit($mysql->error);
}
$download=$mysql->field("download");
$size=$mysql->field("filesize");
$filename=$mysql->field("filename");
$dlfilename=str_replace('.', '_', $filename);

$check=check_folder($mysql, $mysql->field("folder_id"), $userlevel);

if(!is_array($check))
{
 $smarty->assign("message", $check);
 $smarty->display("message.tpl");
 exit();
}
$log->log("D", $CurUser->getid(), $filename);

$sesid = session_id();
clearstatcache();
if (!is_dir('temporary/'.$sesid)) {
	mkdir('temporary/'.$sesid, 0777);
}
if (!file_exists('temporary/'.$sesid.'/'.$filename)) {
	copy('data/'.$download, 'temporary/'.$sesid.'/'.$filename);
}

/********************** SepedaTua ****************************/
// Added by sepedatua on June 05, 2006 - http://www.sepedatua.info/
// Zip-ing the file.
require('libs/archive.php');
$dl = new zip_file("temporary/".$sesid."/".$dlfilename.".zip");
$dl->set_options(array('inmemory' => 1, 'recurse' => 0, 'storepaths' => 0));
$dl->add_files("temporary/".$sesid."/".$filename);
$dl->create_archive();
$dl->download_file();
/************************ EOD ******************************/
rm('temporary/'.$sesid);
$sesid='';
?>
Return current item: @1 File Store