Location: PHPKode > projects > PHPExplorer > modules/zip.php
<?

require_once("../include/varsfuncs.php");
require_once("$instp/include/ziplib.php");
require_once("$instp/include/get_ext.php");

set_time_limit(100);

if(!function_exists("gzopen"))
 if(!@dl("php_zlib.dll"))
 die("<html><script>alert('Impossible d\\'utiliser les fonctions ZIP : \n  * ZLib non chargée !');window.close();</Script></html>");

if(!$arch||!@file_exists($dir.$arch))
 die("<html><script>alert('Dossier ou archive invalide(s)'); window.close();</script></html>");

if(!$ac) $ac="List";

$z = new Zip($dir.$arch);
$l=$z->listContent();

if(strtolower($ac)=="extall"){
if(!@chdir($to)) { $pos="\n  Cause : * Le dossier $to n\\'existe pas"; @mkdir($to,0777);}
if(!$pos) $pos="\n   Cause : * Inconnue";
  if(is_array($z->extract($to,"./")))
   exit("<html><Script>alert('L\\'archive a été extraite dans $to.');window.location.href='$PHP_SELF?dir=$dir&arch=$arch&random=".rand(0,999)."';</Script></html>"); 
  else
    exit("<html><script>alert('Erreur de décompression$pos'); window.location.href='$PHP_SELF?dir=$dir&arch=$arch&random=".rand(0,999)."';");
}

if(strtolower($ac)=="suppression..."||strtolower($ac)=="extraction..."){
  $indx="";
  for($i=0;isset($zct[$i]);$i++){
    if($l[$zct[$i]][folder]==1){
       for($k=0;isset($l[$k]);$k++){
          $x=explode("/",dirname($l[$k][stored_filename])); $x=$x[count($x)-1];
          $w=explode("/",$l[$zct[$i]][stored_filename]); $w=$w[count($w)-2];
          if($x==$w) $indx.=$l[$k][index].",";
       }
      $indx.=$zct[$i].",";
    }else{
      $indx.=$zct[$i].=",";
    }
  }
  if(substr($indx,-1,1)==",") $indx=substr($indx,0,strlen($indx)-1);
  if(strtolower($ac)=="suppression..."){
    $z->deleteByIndex($indx);
   exit("<html><Script>alert('Les fichiers ont été supprimés de l\\'archive.');window.location.href='$PHP_SELF?dir=$dir&arch=$arch&random=".rand(0,999)."';</Script></html>");
  }else{
    if(!@chdir($to)) @mkdir($to,0777);
    $z->extractByIndex($indx,$to,"./");
   exit("<html><Script>alert('Les fichiers ont été extraits dans $to.');window.location.href='$PHP_SELF?dir=$dir&arch=$arch&random=".rand(0,999)."';</Script></html>");
  }
}

if(strtolower($ac)=="list"){
?>
<html>
<head><title>ZipExplorer | <?=$arch?> </title></head>
<Script Language="JavaScript">
function go(url){ window.location.href=url; }
function selall(){ var i=0;
 while(document.forms[0].elements[i]){
  if(document.forms[0].elements[i].type=="checkbox")
document.forms[0].elements[i].checked=!document.forms[0].elements[i].checked; ++i;}}
</Script></head>
<body bgcolor="#777777">
<h2 align="center">Navigateur Zip</h2>
<table align="center" bgcolor="#CCCCCC" cellspacing=0 cellpadding=2 border=2 bordercolor="#000000" width="97%">
<form action="<?=$PHP_SELF?>" method="get" name="f"><input type=hidden name=dir value="<?=$dir?>">
<input type=hidden name="arch" value="<?=$arch?>">
<tr bgcolor="#C0C0C0"><td width="5%" align="center">&nbsp;</td><td width="33%"><b>Nom</b></td>
<td width="21%"><b>Dossier</b></td><td width="13%"><b>Taille</b></td><td width="13%"><b>Compréssé</b></td>
<td width="10%"><b>Ratio</b></td><td width="5%" style="cursor:hand;" align=center onClick="selall();"><b>X</b></td></tr>
<?
for($k=0;isset($l[$k]);$k++){
  $h=$l[$k];  $name=$h[stored_filename]; $isdir=$h[folder]; $id=$h[index]; $sub="";
 if($isdir){ $mdir=dirname($name)."/";?>
<tr><td align="center"><img src="<?=$path."skins/$sk/images/d.gif"?>" border="0" height="16" width="16"></td>
<td><?=$name?></td><td><?=$mdir?></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
<td align=center><input type="checkbox" name="zct[]" value="<?=$id?>" onClick="alert('ATTENTION : le contenu du dossier sera supprimé !');"></td></tr>
<? }else{ $mdir=dirname($name)."/"; $s=$h[size]; $cs=$h[compressed_size]; $un="Bytes"; $uni="Bytes"; $uig=getext($path,$sk,$name);
if($mdir!="./"){$name=explode("/",$name); $name=$name[count($name)-1]; $mmm=explode("/",$mdir);
for($j=0;$mmm[$j];$j++) $sub.=" &nbsp; &nbsp; ";} $ratio=@intval($cs/($s/100)+0,00001);
if($s>1000){$s=substr($s/1000,0,5); $un="Kb"; }if($s>1000){$s=substr($s/1000,0,5); $un="Mb"; }if($s>1000){$s=substr($s/1000,0,5); $un="Gb"; }
if($cs>1000){$cs=substr($cs/1000,0,5); $uni="Kb"; }if($cs>1000){$cs=substr($cs/1000,0,5); $uni="Mb"; }if($cs>1000){$cs=substr($cs/1000,0,5); $uni="Gb"; } ?>
<tr><td align="center"><img src="<?=$uig?>" border="0" height="16" width="16"></td>
<td><?=$sub?><?=$name?></td><td><?=$sub?><?=$mdir?></td><td><?=$s?> <?=$un?></td><td><?=$cs?> <?=$uni?></td>
<td><?=$ratio?> %</td><td align=center><input type="checkbox" name="zct[]" value="<?=$id?>" onClick=""></td></tr>
<? }}if($k==0){ ?><tr><td colspan="7" align=center><b>= Archive vide =</b></td></tr><? } ?>
</table><br><center>
<input type="button" onClick="go('<?=$path?>modules/download.php?get=<?=$dir.$arch?>&fname=<?=$arch?>');" value="Télécharger l'archive" style="width:200;"> &nbsp;
<input type="submit" name="ac" value="Supprimer la séléction" onClick="this.value='Suppression...';" style="width:200;"> &nbsp;
<input type="submit" name="ac" value="Extraire la séléction.." onClick="var d=prompt('Dans quel dossier ?','<?=$dir?>');if(d){document.f.to.value=d;this.value='Extraction...';}else return false;" style="width:200;">
<input type=hidden name=to><br><br><input type=button value="Fermer" style="width:200;" onClick="window.close();"> &nbsp;
<input type=button onClick="var d=prompt('Dans quel dossier ?','<?=$dir?>');if(d){go('<?="$PHP_SELF?arch=$arch&dir=$dir&ac=extall&to="?>'+d);}else{return false}" value="Extraire l'archive dans..." style="width:200;">
</center />
</form></html>
<?
exit();
}
?>
Return current item: PHPExplorer