📄 webftp.php
字号:
</td></tr><? $list = ftp_rawlist($ftp, "-R /"); ftp_close($conn); $i = 0; foreach ($list as $current) { $split = preg_split("[ ]", $current, 9, PREG_SPLIT_NO_EMPTY); if ($split[0] != "total") { $parsed[$i]['isdir'] = $split[0]{0} === "d"; $parsed[$i]['perms'] = $split[0]; $parsed[$i]['number'] = $split[1]; $parsed[$i]['owner'] = $split[2]; $parsed[$i]['group'] = $split[3]; $parsed[$i]['size'] = $split[4]; $parsed[$i]['month'] = $split[5]; $parsed[$i]['day'] = $split[6]; $parsed[$i]['time/year'] = $split[7]; $parsed[$i]['name'] = $split[8]; //echo "<br>".$parsed[$i]['name']; //echo $parsed[$i]['size']; $totalspace += $parsed[$i]['size']; $i++; } }echo "<DIV ALIGN=CENTER><strong>Used space on directory:". size_readable($nlist_total) . " </strong><br></DIV>";echo "<DIV ALIGN=CENTER><strong>Used space on server:". size_readable($totalspace) ." </strong><br></DIV>"; } } else {?> <table style="margin-bottom: 5px;" align="center" bgcolor="#c3d9ff" cellpadding="0" cellspacing="0" width="500"> <tbody><tr> <td class="bubble tl" align="left" valign="top"><img src="corner_tl.gif" class="c" alt=""></td> <td class="bubble" rowspan="2" style="padding: 3px 0pt; font-family: arial; text-align: left; font-weight: bold;"><p align="center"> <table bgcolor="#c3d9ff" border=0> <tr><td><table border=0 bgcolor="#8CAAE7" cellspacing=20><p><font color="#660099"><strong>Directory empty.</strong></font><p><table bgcolor="#c3d9ff" align="left"><tr><td><form action="webftp.php" method=post><?php $cdup=dirname($phpftp_dir); if ($cdup == "") { $cdup="/"; }?><input type="hidden" name="function" value="dir"><input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>"><input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>"><input type="hidden" name="phpftp_dir" value="<?php echo $cdup; ?>"><input type="hidden" name="phpftp_host" value="<?php echo $phpftp_host; ?>"><input type="submit" value="Go up" class="texto2"></form></td></tr></table><?php }?></table><table bgcolor="#c3d9ff" align="center"><tr><td><div>Directory</div><form action="webftp.php" method=post><input type="hidden" name="function" value="mkdir"><input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>"><input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>"><input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>"><input type="hidden" name="phpftp_host" value="<?php echo $phpftp_host; ?>"><input name="new_dir" type="text" class="texto2"><input type="submit" value="Make" class="texto2" style="width:100px;"></form></td><td><div>Files</div><form enctype="multipart/form-data" action="webftp.php" method=post><input type="hidden" name="max_file_size" value="<?php echo $max_file_size ?>"><input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>"><input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>"><input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>"><input type="hidden" name="phpftp_host" value="<?php echo $phpftp_host; ?>"><input type="hidden" name="function" value="put"><input id="my_file_element" name="file_0" type="file" class="texto2"><input type="submit" value="Upload selected" class="texto2"></form><div id="files_list"></div><script> <!-- Create an instance of the multiSelector class, pass it the output target and the max number of files --> var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 6 ); <!-- Pass in the file element --> multi_selector.addElement( document.getElementById( 'my_file_element' ) );</script></td></tr></table></td></tr></table></td> <td class="bubble tr" align="right" valign="top"><img src="corner_tr.gif" class="c" alt=""></td> </tr> <tr> <td class="bubble bl" align="left" valign="bottom"><img src="corner_bl.gif" class="c" alt=""></td> <td class="bubble br" align="right" valign="bottom"><img src="corner_br.gif" class="c" alt=""></td> </tr> </tbody></table> </td> </tr><?php ftp_quit($ftp); phpftp_bottom(); }}/*Change dir function*/function phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory,$phpftp_host) {?><?php $new_directory=$phpftp_dir ."/". $select_directory; phpftp_list($phpftp_user,$phpftp_passwd,$new_directory,$phpftp_host);}/*Make dir function*/function phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir,$phpftp_host) { $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd,$phpftp_host); if ($phpftp_dir == "") { $phpftp_dir="/"; } if (!$ftp) { @ftp_quit($ftp); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_mkdir:phpftp_connect</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { $dir_path = $phpftp_dir . "/" . $new_dir; @ftp_mkdir($ftp,$dir_path); @ftp_quit($ftp); phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir,$phpftp_host); }}; /*Download file function*/function phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file,$phpftp_host) { $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd,$phpftp_host); if ($phpftp_dir == "") { $phpftp_dir="/"; } if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) { @ftp_quit($ftp); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_get:phpftp_connect</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { srand((double)microtime()*1000000); $randval = rand(); $tmpfile="./tmp/" . "/" . $select_file . "." . $randval; if (!ftp_get($ftp,$tmpfile,$select_file,FTP_BINARY)) { ftp_quit($ftp); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_get:ftp_get</strong></font><p><p><a href="webftp.php"<font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { ftp_quit($ftp); global $use_mime_lookup; if ($use_mime_lookup == "1") { $file_mime_type=mime_lookup(substr(strrchr($select_file,"."),1)); } if (!$file_mime_type) { $file_mime_type="application/octet-stream"; } header("Content-Type: " . $file_mime_type); header("Content-Disposition: attachment; filename=\"" . $select_file . "\""); readfile($tmpfile); } @unlink($tmpfile); }}/*Delete function*/function phpftp_delete($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file,$phpftp_host) { $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd,$phpftp_host); if ($phpftp_dir == "") { $phpftp_dir="/"; } if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) { @ftp_quit($ftp); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_delete:phpftp_connect</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { ftp_delete($ftp,$select_file); ftp_quit($ftp); phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir,$phpftp_host); }}/*Remove directory function*/function phpftp_rmdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory,$phpftp_host) { $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd,$phpftp_host); if ($phpftp_dir == "") { $phpftp_dir="/"; } if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) { @ftp_quit($ftp); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_delete:phpftp_connect</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { ftp_rmdir($ftp,$select_directory); ftp_quit($ftp); phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir,$phpftp_host); }}/*File edition function*/function phpftp_edit($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file,$phpftp_host) { $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd,$phpftp_host); if ($phpftp_dir == "") { $phpftp_dir="/"; } if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) { @ftp_quit($ftp); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_get:phpftp_connect</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { srand((double)microtime()*1000000); $tmpfile="./tmp/".$select_file; if (!ftp_get($ftp,$tmpfile,$phpftp_dir."/".$select_file,FTP_BINARY)) { ftp_quit($ftp); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_get:ftp_get</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { ftp_quit($ftp);?><table style="margin-bottom: 5px;" align="center" bgcolor="#c3d9ff" cellpadding="0" cellspacing="0" width="500"> <tbody><tr> <td class="bubble tl" align="left" valign="top"><img src="corner_tl.gif" class="c" alt=""></td> <td class="bubble" rowspan="2" style="padding: 3px 0pt; font-family: arial; text-align: left; font-weight: bold;"><p align="center"> <table align="center"><tr><td class="title" bgcolor="#CCCCFF" colspan="2" align="center"><strong><?echo $select_file;?></strong></td></tr><form method="post" action="webftp.php"><tr><td><textarea rows="25" cols="80" name="source"><?$content = file_get_contents("./tmp/".$select_file);echo $content;?></textarea><br></td></tr><tr><td><input type="hidden" name="function" value="write"><input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>"><input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>"><input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>"><input type="hidden" name="phpftp_host" value="<?php echo $phpftp_host; ?>"><input type="hidden" name="select_file" value="<?php echo $select_file; ?>"><input type="submit" class="texto2" onClick="return confirm_entry_b()" value="Save"></td></tr></table></form></td> <td class="bubble tr" align="right" valign="top"><img src="corner_tr.gif" class="c" alt=""></td> </tr> <tr> <td class="bubble bl" align="left" valign="bottom"><img src="corner_bl.gif" class="c" alt=""></td> <td class="bubble br" align="right" valign="bottom"><img src="corner_br.gif" class="c" alt=""></td> </tr> </tbody></table><? } @unlink($tmpfile); }ftp_quit($ftp);phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir,$phpftp_host);}/*Write function*/function phpftp_write($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file,$phpftp_host,$source) {$source = stripslashes($source);if ($ftpfile = fopen("./tmp/".$select_file,"wb")){fwrite ($ftpfile,$source);fclose($handle);}else { echo "./tmp/".$select_file; echo "cannot fopen"; } if (!$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd,$phpftp_host)) { phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_put:phpftp_connect</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { if ($phpftp_dir) ftp_chdir($ftp,$phpftp_dir); ftp_put($ftp,$select_file,"./tmp/".$select_file,FTP_BINARY); ftp_quit($ftp); unlink("./tmp/".$select_file); phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir,$phpftp_host); }ftp_quit($ftp);}/*Upload file function*/function phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name,$phpftp_host) {for ($i=0;$i < count($_FILES);$i++){$fileindex = 'file_' . $i;if ($_FILES[$fileindex]['name'] != ""){srand((double)microtime()*1000000); $randval = rand(); $tmpfile=$phpftp_tmpdir . "./tmp/" . $_FILES[$fileindex]['name'] . "." . $randval; if (!@move_uploaded_file($_FILES[$fileindex]['tmp_name'], $tmpfile)) { phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_put:move_uploaded_file</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login??</font></a><?php phpftp_bottom(); } else { if (!$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd,$phpftp_host)) { unlink($tmpfile); phpftp_top();?><font color="#ff0000"><strong>Could not connect to FTP. ERROR:phpftp_put:phpftp_connect</strong></font><p><p><a href="webftp.php" <font color=#666666>Re-login?</font></a><?php phpftp_bottom(); } else { if ($phpftp_dir) ftp_chdir($ftp,$phpftp_dir); ftp_put($ftp,$_FILES[$fileindex]['name'],$tmpfile,FTP_BINARY); ftp_quit($ftp); unlink($tmpfile); } }}} phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir,$phpftp_host);}/*Main*/switch($_POST['function']) { case "dir"; phpftp_list($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['phpftp_host']); break; case "cd"; if ($sbutton == "Go in"){ phpftp_cd($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['select_directory'],$_POST['phpftp_host']); } elseif ($sbutton == "Go up") { phpftp_list($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['Dphpftp_dir'],$_POST['phpftp_host']); } elseif ($sbutton == "Remove directory") { phpftp_rmdir($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['select_directory'],$_POST['phpftp_host']); } break; case "get"; if ($_POST['select_file'] == "") { phpftp_list($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['Dphpftp_dir'],$_POST['phpftp_host']); break; } if ($_POST['button'] == "Download file"){ phpftp_get($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['select_file'],$_POST['phpftp_host']); } elseif ($_POST['button'] == "Remove file") { phpftp_delete($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['select_file'],$_POST['phpftp_host']); } elseif ($_POST['button'] == "Edit file") { phpftp_edit($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['select_file'],$_POST['phpftp_host']); } break; case "put"; phpftp_put($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_FILES['userfile']['name'],$_FILES['userfile']['name'],$_POST['phpftp_host']); break; case "write"; phpftp_write($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['select_file'],$_POST['phpftp_host'],$_POST['source']); break; case "mkdir"; phpftp_mkdir($_POST['phpftp_user'],$_POST['phpftp_passwd'],$_POST['phpftp_dir'],$_POST['new_dir'],$_POST['phpftp_host']); break; case ""; if (count($_GET) != NULL){ phpftp_list($_GET['phpftp_user'],$_GET['phpftp_passwd'],$_GET['phpftp_dir'],$_GET['phpftp_host']);} else {phpftp_login();} } ?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -