首页 > 开发 > PHP > 正文

PHP的FTP学习(三)

2024-05-04 22:15:18
字体:
来源:转载
供稿:网友
By Vikram Vaswani
Melonfire
November 07, 2000
现在,我们已经接触了PHP关于FTP的大量函数,但这仅仅只是函数,离我们的目标还远远不够,要显示出这些函数的真正力量,我们应该建立一个程序,这个程序能以WEB方式上传,下载文件---这就是我们将要做的!

在我们进入代码前,我想要告诉大家的是,这个例子仅仅只是为了向大家解释PHP的各种FTP函数的使用,很多方面还不够完善,比如说,错误分析等,至于你想应用到你自己的程序中,你应该进行一些修改!

程序包括以下几个文件:
index.html - 登录文件

actions.php - 程序必需的FTP代码

include.php - 程序主界面,它显示文件列表和控制按钮。

让我们从 "index.html"开始吧:  
--------------------------------------------------------------------------------
<table border=0 align=center>
<form action="actions.php" method=post>
<input type=hidden name=action value=CWD>
<tr>
<td>
Server
</td>
<td>
<input type=text name=server>
</td>
</tr>

<tr>
<td>
User
</td>
<td>
<input type=text name=username>
</td>
</tr>

<tr>
<td>
Password
</td>
<td>
<input type=password name=password>
</td>
</tr>

<tr>
<td colspan=2 align=center>
<input type="submit" value="Beam Me Up, Scotty!">
</td>
</tr>

</form>
</table>
--------------------------------------------------------------------------------
这是一个登录表单,有一个服务器名称、用户名、密码,输入框。输入的变量将会被存到$server, $username 和 $password 变量中,表单提交后,调用actions.php,它将初始化FTP联接。

注意那个“hidden” 它传给action.php一个变量$action ,值为CWD。


这是action.php文件的源码:
--------------------------------------------------------------------------------
<html>
<head>
<basefont face=Arial>
</head>
<body>

<!-- the include.php interface will be inserted into this page -->

<?

//检查表单传来的数据,不全则报错,要想程序完善的话,这里应该有更全的输入检测功能
if (!$server || !$username || !$password)
{
echo "提交数据不全!";
}
else
{
// keep reading
}

?>

</body>
</html>
--------------------------------------------------------------------------------


接下来是变量 "actions". 程序允许以下的action:

"action=CWD"

改变工作目录

"action=Delete"
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表