Файл: ftp/arhdir.php
Строк: 104
<?php
error_reporting(0);
$k=trim($_GET['k']); include("key.php");
$d=rawurldecode(trim($_GET['d'])); $n=rawurldecode(trim($_GET['n']));
if ($d==NULL) {$d="";} if ($n==NULL) {$n=preg_replace("~.*/([^/]*)~m","\1",$d);
$d=preg_replace("~(.*)/[^/]*~m","\1",$d);}
$rd=rawurlencode($d); $rn=rawurlencode($n);
require_once '../api_core/apicms_system.php';
require_once '../api_core/head.php';
$d=str_replace(".|htaccess",".htaccess",$d);
$n=str_replace(".|htaccess",".htaccess",$n);
$nm=trim($_POST['nm']); $ch=trim($_GET['ch']);
if ($nm<>NULL) {
$repl=array("\"=>"",":"=>"","*"=>"","?"=>"","""=>"","<"=>"",">"=>"","|"=>"");
$nm=trim(strtr($nm,$repl));
include("repl.php"); $nm=u2t($nm);
if (($nm==".")||($nm=="..")) {$nm="";}
}
if (($nm==NULL)||(strlen($ch)<>3)) {
$num=@file_get_contents("allnumbd.dat"); $nar=NULL;
$num++; $nar=$num; if ($num>99999999) {$num=0;}
$f=@fopen("allnumbd.dat","w"); @fwrite($f,$num); @fclose($f);
if ($d=="/") {$d="";} $n=str_replace("$","$$",$n); $d=str_replace("$","$$",$d);
$vl=$d."/".$n."/".preg_replace("~([^.]*).*~m","\1",$n).".zip";
echo'<div class="subhead"><form action="'.$dftp.'/arhdir.php?k='.$k.'&d='.$rd.'&n='.$rn.'" method="POST">
Архивировать в:<br/>
<input name="nm'.$nar.'" type="text" value="'.$vl.'" maxlength="250"/><br/>
<b>CHMOD</b>:
<input name="chf" type="text" value="644" size="3" maxlength="3" format="*N"/>
<input type="submit" value="Архивировать"><br/>
</form></div>';
} else {
if (($ftp=@ftp_connect($sr))&&(@ftp_login($ftp,$lg,$ps))) {
@ftp_pasv($ftp,true); @ftp_chdir($ftp,"$d/$n"); $curr=@ftp_pwd($ftp);
if ((substr($nm,-1)<>"/")&&($curr<>$nm)) {
function scan($dir,$kl=100,$sz=3145728) {
global $ftp; $arr=NULL; $ckl=0; $csz=0; @ftp_chdir($ftp,$dir);
if ($lst=@ftp_nlist($ftp,".")) {
for ($i=0;$i<count($lst);$i++) {$ckl++;
if ($ckl>$kl) {$ckl--; $arr['err']="ck"; break;}
$fnm=trim($lst[$i]);
if (strpos($fnm,$dir)!==0) {$fnm=str_replace('//','/',$dir.'/'.$fnm);}
$fln=preg_replace("~.*/([^/]*)~","\1",$fnm);
if (($fln<>".")&&($fln<>"..")) {
$size=ftp_size($ftp,$fnm); $csz=$csz+$size;
if ($csz>=$sz) {$csz=$csz-$size; $ckl--; $arr['err']="sz"; break;}
if ($size===-1) {
$arr['d'][]=$fnm;
if ($lt=scan($fnm,$kl-$ckl,$sz-$csz)) {
$arr=array_merge_recursive($arr,$lt);
if ($lt['sz']>0) {$csz=$csz+$lt['sz'];} $ckl=$ckl+$lt['ck'];
}
} else {$arr['f'][]=$fnm;}
}
}
$arr['sz']=$csz; $arr['ck']=$ckl;
return $arr;
} else {return false;}
}
$ar=scan($curr);
if (($ar['f']<>NULL)||($ar['d']<>NULL)) {
$tp=strtolower(preg_replace("~.*.([^.]*)~m","\1",$nm));
@mkdir("data/$k",0777);
if ($ar['d']<>NULL) {
for ($i=0;$i<count($ar['d']);$i++) {
@mkdir("data/$k/".preg_replace("~^".$curr."/~","",$ar['d'][$i]),0777);
}
}
if ($ar['f']<>NULL) {
for ($i=0;$i<count($ar['f']);$i++) {
@ftp_get($ftp,"data/$k/".preg_replace("~^".$curr."/~","",$ar['f'][$i]),$ar['f'][$i],FTP_BINARY);
}
}
if (($tp=="zip")||($tp=="jar")) {
include_once('pclzip.php'); $zip=new PclZip("data/$k.zip");
if ($zip->create("data/$k",PCLZIP_OPT_REMOVE_PATH,"data/$k",PCLZIP_OPT_COMMENT,$cmm)<>0) {
@ftp_put($ftp,"$nm","data/$k.zip",FTP_BINARY);
} @unlink("data/$k.zip");
} else {
include_once("tar.php"); $tar=new Archive_Tar("data/$k.tar");
if ($tar->createModify("data/$k","","data/$k")) {
@ftp_put($ftp,"$nm","data/$k.tar",FTP_BINARY);
} @unlink("data/$k.tar");
}
include_once("rmdir.php"); rdir("data/$k");
}
}
@ftp_close($ftp);
header("Location: $dftp/ftp.php?k=$k&d=$rd&n=$rn"); exit;
} else {
}
}
apicms_foot();
?>