Location: PHPKode > projects > @1 File Store > zipd.php
<?
session_start();
if(isset($_GET["id"]) && $_GET["id"]!="") {
	$fileid=$_GET["id"];
} else {
	exit("Bad request");
}
$MustLogin=1|2|4;
$sesid = session_id();
require_once("libs/header.php");
require_once(LIBPATH."multipage.php");

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);
}

rm('temporary/'.$sesid);
clearstatcache();
mkdir('temporary/'.$sesid, 0777);
$id = $_GET['id'];

require_once("libs/header.php");
require_once("libs/databasetree.php");
$tree=new databasetree($mysql, DB_PREFIX."folders");
$folder_list=$tree->get_array("download", "^");

if (!array_key_exists($id, $folder_list)) { exit("Bad request"); }
/*
$folisttree=new databasetree($mysql, DB_PREFIX."folders");
$folisttreeresult=$folisttree->get_array("Root Folder", "...&nbsp;&nbsp;");
*/
$test1 = $folder_list;
$flist = $folder_list;

$group=array();
foreach ($folder_list as $key => $value) {
	$sql3 = "SELECT group_id, folder_id FROM `".DB_PREFIX."access_list` WHERE folder_id='".$key."'";
	if(!$mysql->query($sql3)) { exit($mysql->error); }

	while(!$mysql->EOF) {
		$group[$mysql->field("folder_id")]=$mysql->field("group_id");
		$mysql->movenext();
	}
}


foreach ($test1 as $test1key => $test1value) {
	if(!array_key_exists($test1key, $group) and $test1key!=0) {
		unset($flist[$test1key]);
	}
}

$dir = '';
$files = '';
$filecopy = 0;

foreach ($flist as $k => $v) {
	$vfolder = str_replace('^', '', $v);
	$vfolder = str_replace(' ', '_', $vfolder);
	$vslash = $vfolder.'/';
	$countv = substr_count($v, '^');

	if ($countv=='0') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir0 = 'temporary/'.$sesid.'/';
/*		mkdir($dir0, 0777);
		echo 'mkdir: '.$dir0;
		echo '<br>';
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				copy('data/'.$download, $dir0.'/'.$filename);
			}
		}
*/	} else if ($countv=='1') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir1 = $dir0.'/'.$vfolder;
		mkdir($dir1, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) {
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir1.'/'.$filename);
			}
		}
	} else if ($countv=='2') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir2 = $dir1.'/'.$vfolder;
		mkdir($dir2, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir2.'/'.$filename);
			}
		}
	} else if ($countv=='3') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir3 = $dir2.'/'.$vfolder;
		mkdir($dir3, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir3.'/'.$filename);
			}
		}
	} else if ($countv=='4') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir4 = $dir3.'/'.$vfolder;
		mkdir($dir4, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir4.'/'.$filename);
			}
		}
	} else if ($countv=='5') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir5 = $dir4.'/'.$vfolder;
		mkdir($dir5, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir5.'/'.$filename);
			}
		}
	} else if ($countv=='6') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir6 = $dir5.'/'.$vfolder;
		mkdir($dir6, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir6.'/'.$filename);
			}
		}
	} else if ($countv=='7') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir7 = $dir6.'/'.$vfolder;
		mkdir($dir7, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir7.'/'.$filename);
			}
		}
	} else if ($countv=='8') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir8 = $dir7.'/'.$vfolder;
		mkdir($dir8, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir8.'/'.$filename);
			}
		}
	} else if ($countv=='9') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir9 = $dir8.'/'.$vfolder;
		mkdir($dir9, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir9.'/'.$filename);
			}
		}
	} else if ($countv=='10') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir10 = $dir9.'/'.$vfolder;
		mkdir($dir10, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir10.'/'.$filename);
			}
		}
	} else if ($countv=='11') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir11 = $dir10.'/'.$vfolder;
		mkdir($dir11, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir11.'/'.$filename);
			}
		}
	} else if ($countv=='12') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir12 = $dir11.'/'.$vfolder;
		mkdir($dir12, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir12.'/'.$filename);
			}
		}
	} else if ($countv=='13') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir13 = $dir12.'/'.$vfolder;
		mkdir($dir13, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir13.'/'.$filename);
			}
		}
	} else if ($countv=='14') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir14 = $dir13.'/'.$vfolder;
		mkdir($dir14, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir14.'/'.$filename);
			}
		}
	} else if ($countv=='15') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir15 = $dir14.'/'.$vfolder;
		mkdir($dir15, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir15.'/'.$filename);
			}
		}
	} else if ($countv=='16') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir16 = $dir15.'/'.$vfolder;
		mkdir($dir16, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir16.'/'.$filename);
			}
		}
	} else if ($countv=='17') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir17 = $dir16.'/'.$vfolder;
		mkdir($dir17, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir17.'/'.$filename);
			}
		}
	} else if ($countv=='18') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir18 = $dir17.'/'.$vfolder;
		mkdir($dir18, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir18.'/'.$filename);
			}
		}
	} else if ($countv=='19') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir19 = $dir18.'/'.$vfolder;
		mkdir($dir19, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir19.'/'.$filename);
			}
		}
	} else if ($countv=='20') {
		if ($k == $id) { $matchv = $vfolder; }
		$dir20 = $dir19.'/'.$vfolder;
		mkdir($dir20, 0777);
		$file_list= '';
		$file_list=array();
		$SQL="SELECT `".DB_PREFIX."file_list`.*, `".DB_PREFIX."users`.`login`, `".DB_PREFIX."users`.`real_name`";
		$SQL.=" FROM `".DB_PREFIX."file_list` LEFT JOIN `".DB_PREFIX."users` ON `".DB_PREFIX."file_list`.`user_id`=`".DB_PREFIX."users`.`id`";
		$SQL.=" WHERE `".DB_PREFIX."file_list`.`folder_id`='".$k."'";
		$SQL.=" ORDER BY `".DB_PREFIX."file_list`.`".ORDER_FIELD."`";
		if(!$mysql->query($SQL)) { exit($mysql->error); }
		$file_list=array();
		while(!$mysql->EOF) {
			$file_list[]=$mysql->arr;
			$mysql->movenext();
		}
		if ($file_list!='') {
			foreach ($file_list as $file) {
				$download=$file['download'];
				$filename=$file['filename'];
				$filetype=$file['file_type'];
				$filetype='.'.$filetype;
				if (strpos($files, $filename)) { 
					$filename=str_replace($filetype, '', $filename);
					$filecopy=$filecopy+1;
					$filename=$filename.'_copy'.$filecopy.$filetype;
				}
				$files .= $filename.', ';
				copy('data/'.$download, $dir20.'/'.$filename);
			}
		}
	}
}

function currentLocation( $folderid ) {
	global $smarty, $loc ;
	$SQL = mysql_query("SELECT folder_name, id, parent FROM fstore_folders WHERE id=$folderid ");
	$row = mysql_fetch_array( $SQL );
	if( $row['parent'] == 0 )
		$location = "/{$row['folder_name']}";
	else {
		$location = "/{$row['folder_name']}";
		currentLocation( $row['parent'] );
	}
	$loc .= $location ;
}
currentLocation( $id );
/*
$loc = str_replace(' ', '_', $loc);
require('libs/archive.php');
$bdir = 'temporary/'.$sesid;
$addf = $bdir.$loc;
$dl = new zip_file($bdir.'/'.$matchv.'.zip');
$dl->set_options(array('overwrite' => 1, 'inmemory' => 1, 'recurse' => 1, 'storepaths' => 0));
$dl->add_files($addf);
$dl->create_archive();
$dl->download_file();
rm('temporary/'.$sesid);
$sesid = '';
*/
print_r('<pre>');
print_r('<br>========================test1<br>');
print_r($test1);
print_r('<br>========================folder_list<br>');
print_r($folder_list);
print_r('<br>========================flist<br>');
print_r($flist);
print_r('<br>========================group<br>');
print_r($group);
print_r('<br>========================aclid<br>');
print_r($aclid);
print_r('<br>========================userlevel<br>');
print_r($userlevel);
print_r('<br>========================<br>');
print_r('<br>========================<br>');
print_r('</pre>');
?>
Return current item: @1 File Store