","\""),array("&","<",">","""),$what); } function unfilterHTML($what){ return str_replace(array("<",">",""","&"),array("<",">","\"","&"),$what); } $scriptName=basename($_SERVER["SCRIPT_NAME"]); $scriptName=filterHTML($scriptName); if($do=="getSource"){ // Download method depends on the browser $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=\"zip2ftp.php\""); }else{ header("Content-Disposition: attachment; filename=\"zip2ftp.php\""); } header("Content-Description: File Transfert"); // Send file readfile($scriptName); // Send e-mail if needed (for usage statistics) if(strpos($user_agent,"bot")===false && strpos($_SERVER["SERVER_NAME"],"alishomepage.com")===false){ mail("opensource@alishomepage.com","ZIP2FTP Interface: another one downloaded :)","This part will be referred to when the browser sends out no referrer information\n\nServer name: ".$_SERVER["SERVER_NAME"]."\nScript name: ".$_SERVER["SCRIPT_NAME"]."\nTranslated path: ".$_SERVER["PATH_TRANSLATED"]."\n\nDownloader's info (the referrer is most useful, user agent is to detect bots)\n\nUser agent: ".$_SERVER["HTTP_USER_AGENT"]."\nReferrer: ".$_SERVER["HTTP_REFERER"]."\nRequest URL: ".$_SERVER["REQUEST_URI"],"From: \"Ali's Open Source Initiative\" "); } die(); } $port=intval($port); if(!$port || $port<1 || $port>65535){ $port=21; } if(file_exists(where_to_find_config)){ include(where_to_find_config); } // PHP < 5 didn't have sys_get_temp_dir if(!is_callable('sys_get_temp_dir',false)) { function sys_get_temp_dir() { $temp=""; if($temp=getenv('TMP')){ return $temp; } if($temp=getenv('TEMP')){ return $temp; } if($temp=getenv('TMPDIR')){ return $temp; } $temp=tempnam('', ''); if(file_exists($temp)){ unlink($temp); return dirname($temp); } return $temp; } } // On some systems, the zip functions do not exist. In this case, try to use // the "unzip" command (available by default on most Linux systems) // Code written by bisqwit at iki dot fi on the zip_open function's comments // on the PHP manual. Thanks to Radek from Poland for telling me about it. if(!is_callable("zip_open",false)){ function ShellFix($s) { return "'". str_replace("'", "'\''", $s)."'"; } function zip_open ($s) { $fp = @fopen ($s, 'rb'); if(!$fp ) return false; $lines = Array(); $cmd = 'unzip -v '.shellfix( $s); exec($cmd, $lines); $contents = Array(); $ok=false; foreach($lines as $line) { if($line[0]== '-') { $ok=!$ok; continue; } if(!$ok) { continue; } $length = (int)$line ; $fn = trim(substr ($line,58)); $contents[] = Array('name' => $fn, 'length' => $length); } return Array('fp' => $fp, 'name' => $s , 'contents' => $contents , 'pointer' => -1); } function zip_read(&$fp) { if(!$fp ) return false; $next = $fp ['pointer'] + 1; if( $next >= count($fp['contents' ])) return false; $fp['pointer' ] = $next; return $fp['contents'][$next]; } function zip_entry_name (&$res) { if(!$res) return false ; return $res['name' ]; } function zip_entry_filesize(&$res ) { if(!$res) return false; return $res['length']; } function zip_entry_open (&$fp, &$res) { if(!$res ) return false; $cmd = 'unzip -p '.shellfix($fp['name' ]).' '.shellfix($res[ 'name']); $res['fp'] = popen($cmd, 'r'); return !! $res['fp']; } function zip_entry_read(&$res, $nbytes) { $contents = ''; while (!feof($res['fp'])) { $contents .= fread($res['fp'], 8192); } return $contents; } function zip_entry_close(&$res) { fclose($res['fp' ]); unset($res['fp']); } function zip_close(&$fp) { fclose( $fp['fp']); } } ?> ZIP 2 FTP

Ali's ZIP 2 FTP Interface

"; if(!$username || strlen($username)<1) { $username="anonymous"; } $portNumber=intval($portNumber); if(!$portNumber || $portNumber<1 || $portNumber>65535){ $portNumber=21; } $zip=zip_open($_FILES["uplFile"]["tmp_name"]); $uplTotal=0; if($zip){ if($conn_id=ftp_connect($serverName,$portNumber)){ if(ftp_login($conn_id,$userName,$passWord)){ if($usePassive==1 || defined("DontUseActiveFTP")){ $usePassive=true; }else{ $usePassive=false; } $folder=str_replace(array("&slash;","&"),array("/","&"),stripslashes(str_replace(array("<","&","\\\\"),array("<","&","&slash;"),$folder))); if(strlen($folder)<1){ $folder="/"; } if(!ftp_chdir($conn_id,$folder)){ echo "Cannot change current directory to $folder, creating directories..."; } echo "Changed current directory to $folder, pwd is ".ftp_pwd($conn_id).""; } foreach(explode('/',$complete_path) AS $k){ if(strlen($k)>0){ $do_cdUp++; if(!ftp_chdir($conn_id,$k)){ ftp_mkdir($conn_id,$k); if(!ftp_chdir($conn_id,$k)){ echo "Change current dir to $k FAILED!! Better die()!"; die(); } } echo "Changed current directory to $k, pwd is ".ftp_pwd($conn_id)."