<?
if($do=="getSource"){
$scriptName=stripslashes(basename($SCRIPT_FILENAME));
$user_agent=strtolower($_SERVER["HTTP_USER_AGENT"]);
header("Content-type: application/force-download");
if((is_integer(strpos($user_agent,"msie")))&&(is_integer(strpos($user_agent,"win")))){
header("Content-Disposition: filename=\"$scriptName\"");
}else{
header("Content-Disposition: attachment; filename=\"$scriptName\"");}
header("Content-Description: File Transfert");
readfile($scriptName);
die();}
$zipFileSizeLimit_MB=8;
echo "<meta http-equiv='Content-Type' content='text/html;charset=windows-1254'>\n<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-9'>\n<title>ZIP 2 FTP</title>\n<style>BODY{background:#F0F0F0;font-family:verdana,arial,helvetica;font-size:
13;color:#121212;cursor:default}TD{font-size:13}H1{font-size:28}A{text-decoration:none;color:
#2B5796}A:hover{color:#FF6262;text-decoration:underline}</style>\n<center><h1>Ali's ZIP 2 FTP Interface</h1>\n<form action=# method=POST enctype=multipart/form-data>\n<table width=100% border=0 cellpadding=3>\n<tr><td align=right width=47%>Hostname : </td><td><input size=20 name=serverName type=text maxlength=128 value=''></td></tr>\n<tr><td align=right>Username : </td><td><input size=20 name=userName type=text maxlength=128 value=''></td></tr>\n<tr><td align=right>Password : </td><td><input size=20 name=passWord type=password maxlength=128 value=''></td></tr>\n<tr><td align=right>Folder in which to upload : </td><td><input size=20 name=requestedDir type=text></td></tr>\n<tr><td align=right>ZIP file : </td><td><input name=MAX_FILE_SIZE type=hidden value=".($zipFileSizeLimit_MB*1048576)."><input type=file name=uplfile size=15></td></tr>\n<tr><td align=right>Use passive mode FTP ? </td><td><select name=usePassiveFTP><option selected value=0>No<option value=1>Yes</select></td></tr></table><br>\n<input type=submit value='Go !'></form>\n<b>WHAT THIS SCRIPT DOES</b>: This script will take your ZIP file, which has to be smaller than $zipFileSizeLimit_MB MB, and decompress it in the folder on the FTP server you specify. While doing it, it will also give you information about what it has done at the end of this page...<br><br>\n<font size=1>(click <a href=?do=getSource>here</a> to get the PHP source of this ZIP 2 FTP interface)\n</font><font size=2><br><br></font><font
size=1>\n";
error_reporting(0);
$zip=zip_open($uplfile);
$conn_id=ftp_connect($serverName);
$uplTotal=0;
if($zip && $conn_id && ftp_login($conn_id,$userName,$passWord)){
if($usePassive==1){
$usePassive=true;
}else{
$usePassive=false;}
if(!ftp_chdir($conn_id,$requestedDir)){
$up_we_go=0;
$requestedDir=str_replace("\\'","'",$requestedDir);
foreach(explode('/',str_replace("\\","/",$requestedDir)) AS $k){
ftp_mkdir($conn_id,$k);
if(ftp_chdir($conn_id,$k)){
$up_we_go++;}}
for($up_we_go=$up_we_go;$up_we_go>0;$up_we_go--){
ftp_cdup($conn_id);}
if(!ftp_chdir($conn_id,$requestedDir)){
echo "<br>Change current dir to <b>$requestedDir</b> FAILED!! Better die()!";
die();}}
echo "<br>Change current dir to <b>$requestedDir</b> OK<br><ul>\n";
ftp_pasv($conn_id,$usePassive);
$current_path="";
$do_cdUp=0;
while($zip_entry=zip_read($zip)){
if(zip_entry_filesize($zip_entry)>0){
if(dirname(zip_entry_name($zip_entry))!="."){
$complete_path=dirname(zip_entry_name($zip_entry));
}else{
$complete_path="";}
$complete_name=basename($path.zip_entry_name($zip_entry));
if($complete_path!=$current_path){
for($do_cdUp=$do_cdUp;$do_cdUp>0;$do_cdUp--){
ftp_cdup($conn_id);
echo "..</ul>";}
foreach(explode('/',$complete_path) AS $k){
$do_cdUp++;
if(!ftp_chdir($conn_id,$k)){
ftp_mkdir($conn_id,$k);
if(!ftp_chdir($conn_id,$k)){
echo "Change current dir to <b>$k</b> FAILED!! Better die()!";
die();}}
echo "Change current dir to <b>$k</b> OK<br><ul>\n";
$current_path=$complete_path;}}
if(zip_entry_open($zip,$zip_entry,"r")){
$tempName=strtolower(base_convert(rand(0,46656),10,36));
while(file_exists("$tempName.tmp")){
$tempName=strtolower(base_convert(rand(0,46656),10,36));}
$fd=fopen("$tempName.tmp",'w');
fwrite($fd,zip_entry_read($zip_entry,zip_entry_filesize($zip_entry)));
fclose($fd);
if(ftp_put($conn_id,$complete_name,"$tempName.tmp",FTP_BINARY)){
echo "Upload file <b>$complete_name</b> OK<br>\n";
$uplTotal++;
}else{
echo "Upload file <b>$complete_name</b> FAILED!! Better die()!";
unlink("$tempName.tmp");
die();}
unlink("$tempName.tmp");
zip_entry_close($zip_entry);}}}
zip_close($zip);
ftp_close($conn_id);
echo "<br><br>Upload of $uplTotal files OK";}
?>
|