web方式ftp_PHP教程
/* This software came from http://inebria.com/ */
/* Copyright (c) 2000
Paul Southworth. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* Configuration Options */
$phpftp_host="localhost";
$phpftp_version="2.2";
/* Comment this out if you don't want the version footer */
$show_version_footer=1;
/* How large a file will you accept? You may also need to edit your
php.ini file and change upload_max_filesize appropriately */
$max_file_size="1000000";
/* The temporary directory $phpftp_tmpdir must exist and be writable
by your web server.
Hint: mkdir /var/tmp/xfers && chmod 1777 /var/tmp/xfers */
$phpftp_tmpdir="/var/tmp/xfers";
/* $use_mime_lookup
Turning this on creates a dependency upon the
http://www.inebria.com/mime_lookup/ MIME type lookup library.
Setting this variable to "1" enables it. "0" disables.
If you turn it on, put the mime_lookup.php file in the same directory
as ftp.php and uncomment the 'include("mime_lookup.php");' statement. */
$use_mime_lookup="0";
/* include("mime_lookup.php"); */
/* We enclose the top and bottom in functions because sometimes
we might not send them (ie, in a file-download situation) */
function phpftp_top() {
global $phpftp_version;
?>
}
function phpftp_bottom() {
global $phpftp_version;
global $show_version_footer;
?>
if (isset($show_version_footer)) {
?>
This is PHP FTP
version
}
?>
}
/* This is the form used for initially collecting username/passwd */
function phpftp_login() {
phpftp_top();
?>
phpftp_bottom();
}
/* This function does not return TRUE/FALSE - it returns the value of
$ftp, the current FTP stream. */
function phpftp_connect($phpftp_user,$phpftp_passwd) {
global $phpftp_host;
$ftp = ftp_connect($phpftp_host);
if ($ftp) {
if (ftp_login($ftp,$phpftp_user,urldecode($phpftp_passwd))) {
return $ftp;
}
}
}
function phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir) {
global $phpftp_host;
phpftp_top();
?>
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if (!$ftp) {
?>
FTP login failed!
Start over?
phpftp_bottom();
} else {
if (!$phpftp_dir) {
$phpftp_dir=ftp_pwd($ftp);
}
if (!@ftp_chdir($ftp,$phpftp_dir)) {
?>
Can't enter that directory!
$phpftp_dir=ftp_pwd($ftp);
}
echo "Current host: " . $phpftp_host . "
\n";
echo "Current directory: " . $phpftp_dir . "
\n";
if ($phpftp_dir == "/") {
$phpftp_dir="";
}
if ($contents = ftp_rawlist($ftp,"")) {
$d_i=0;
$f_i=0;
$l_i=0;
$i=0;
while ($contents[$i]) {
$item[] = split("[ ]+",$contents[$i],9);
$item_type=substr($item[$i][0],0,1);
if ($item_type == "d") {
/* it's a directory */
$nlist_dirs[$d_i]=$item[$i][8];
$d_i++;
} elseif ($item_type == "l") {
/* it's a symlink */
$nlist_links[$l_i]=$item[$i][8];
$l_i++;
} elseif ($item_type == "-") {
/* it's a file */
$nlist_files[$f_i]=$item[$i][8];
$nlist_filesize[$f_i]=$item[$i][4];
$f_i++;
} elseif ($item_type == "+") {
/* it's something on an anonftp server */
$eplf=split(",",implode(" ",$item[$i]),5);
if ($eplf[2] == "r") {
/* it's a file */
$nlist_files[$f_i]=trim($eplf[4]);
$nlist_filesize[$f_i]=substr($eplf[3],1);
$f_i++;
} elseif ($eplf[2] == "/") {
/* it's a directory */
$nlist_dirs[$d_i]=trim($eplf[3]);
$d_i++;
}
} /* ignore all others */
$i++;
}
?>
Directories |
Files |
推荐阅读
-
CentOS 7中 Apache Web 服务器安装配置教程
-
浅析CentOS6.8安装MySQL8.0.18的教程(RPM方式)
-
[教程+分享]具有良好体验度的Web注册系统
-
人生日历网页版怎么用?人生日历网页版使用教程(附人生日历web版地址)
-
使用Python下的XSLT API进行web开发的简单教程
-
浅谈Web页面向后台提交数据的方式和选择
-
使用HTML5的Notification API制作web通知的教程
-
微软Edge浏览器快捷方式在哪里?Edge创建桌面快捷的详细教程
-
基于JS抓取某高校附近共享单车位置 使用web方式展示位置变化代码实例
-
YY伴侣软件歌词显示和歌曲导入方式图文教程