現(xiàn)在終于到了我們的第三個(gè)文件,include.php 它為程序建立起一個(gè)用戶界面。

"include.php" 包含三個(gè)表單,一些PHP代碼獲取當(dāng)前的目錄列表并將它們存入三個(gè)變量
$files (包括當(dāng)前目錄下 " /> 一道本av免费不卡播放,一级做a爰片久久毛片苍井优,亚洲精品人成电影网

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PHP的FTP學(xué)習(xí)(二)[轉(zhuǎn)自奧索]


現(xiàn)在終于到了我們的第三個(gè)文件,include.php 它為程序建立起一個(gè)用戶界面。

"include.php" 包含三個(gè)表單,一些php代碼獲取當(dāng)前的目錄列表并將它們存入三個(gè)變量
$files (包括當(dāng)前目錄下的文件),
$file_sizes (相應(yīng)的文件大小),
and $dirs (包含子目錄名)

第一個(gè)表單使用$dirs 產(chǎn)生一個(gè)下拉式目錄列表,對應(yīng)于“action=CWD”。

第二個(gè)表單使用$files  $file_sizes創(chuàng)建一個(gè)可用的文件列表,每一個(gè)文件使用一個(gè)checkbox。這個(gè)表單的action對應(yīng)于"action=Delete" and "action=Download"

第三個(gè)表單用來上傳一個(gè)文件到FTP站點(diǎn),如下:
--------------------------------------------------------------------------------
<form enctype="multipart/form-data" action=actions.php4 method=post>
...
<input type=file name=upfile>
...
</form>
--------------------------------------------------------------------------------
當(dāng)php以這種方式接收到一個(gè)文件名,一些變量就產(chǎn)生了,這些變量指定文件的大小,一個(gè)臨時(shí)的文件名以及文件的類型,最初的文件名存在$upfile_name,一旦上傳后文件名便存入$upfile中(這個(gè)變量是由php自己創(chuàng)建的)
通過這些信息,我們就可以創(chuàng)建以下的語句了:
--------------------------------------------------------------------------------
ftp_put($result, $upfile_name, $upfile, FTP_BINARY);
--------------------------------------------------------------------------------
以下是代碼列表:
--------------------------------------------------------------------------------
<!-- code for index.html begins here -->
<html>
<head>
<basefont face=arial>
</head>

<body>

<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>

</body>
</html>

<!-- code for index.html ends here -->
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
<!-- code for actions.php begins here -->

<html>
<head>
<basefont face=Arial>
</head>
<body>

<?
/*
--------------------------------------------------------------------------------
DISCLAIMER:

This is use-at-your-own-risk code.

It is meant only for illustrative purposes and is not meant for production environments. No warranties of any kind are provided to the user.

You have been warned!

All code copyright Melonfire, 2000. Visit us at http://www.melonfire.com
--------------------------------------------------------------------------------
*/

// function to connect to FTP server
function connect()
{
global $server, $username, $password;
$conn = ftp_connect($server);
ftp_login($conn, $username, $password);
return $conn;
}


// main program begins

// check for valid form entries else print error
if (!$server
!$username
!$password)
{
echo "Form data incomplete!";
}
else
{


// connect
$result = connect();

// action: change directory
if ($action == "CWD")
{

// at initial stage $rdir does not exist
// so assume default directory
if (!$rdir)
{
$path = ".";
}
// get current location $cdir and add it to requested directory $rdir
else
{
$path = $cdir . "/" . $rdir;
}

// change to requested directory
ftp_chdir($result, $path);

}

// action: delete file(s)
else if ($action == "Delete")
{

ftp_chdir($result, $cdir);

// loop through selected files and delete
for ($x=0; $x<sizeof($dfile); $x++)
{
ftp_delete($result, $cdir . "/" . $dfile[$x]);
}

}
// action: download files
else if ($action == "Download")
{

ftp_chdir($result, $cdir);

// download selected files
// IMPORTANT: you should specify a different download location here!!
for ($x=0; $x<sizeof($dfile); $x++)
{
ftp_get($result, $dfile[$x], $dfile[$x], FTP_BINARY);
}

}
// action: upload file
else if ($action == "Upload")
{

ftp_chdir($result, $cdir);

// put file

/*
a better idea would be to use
$res_code = ftp_put($result, $HTTP_POST_FILES["upfile"]["name"],
$HTTP_POST_FILES["upfile"]["tmp_name"], FTP_BINARY);
as it offers greater security
*/
$res_code = ftp_put($result, $upfile_name, $upfile, FTP_BINARY);


// check status and display
if ($res_code == 1)
{
$status = "Upload successful!";
}
else
{
$status = "Upload error!";
}

}

// create file list
$filelist = ftp_nlist($result, ".");

// and display interface
include("include.php");

// close connection
ftp_quit($result);

}
?>

</body>
</html>

<!-- code for actions.php ends here -->
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
<!-- code for include.php begins here -->

<?

// get current location
$here = ftp_pwd($result);

/*
since ftp_size() is quite slow, especially when working
on an array containing all the files in a directory,
this section performs an ftp_size() on all the files in the current
directory and creates three arrays.
*/

// array for files
$files = Array();

// array for directories
$dirs = Array();

// array for file sizes
$file_sizes = Array();

// counters
$file_list_counter = 0;
$dir_list_counter = 0;

// check each element of $filelist
for ($x=0; $x<sizeof($filelist); $x++)
{
if (ftp_size($result, $filelist[$x]) != -1)
{
// create arrays
$files[$file_list_counter] = $filelist[$x];
$file_sizes[$file_list_counter] = ftp_size($result, $filelist[$x]);
$file_list_counter++;
}
else
{
$dir_list[$dir_list_counter] = $filelist[$x];
$dir_list_counter++;
}
}

?>

<!-- header - where am I? -->
<center>
You are currently working in <b><? echo $here; ?></b>
<br>
<!-- status message for upload function -->
<? echo $status; ?>
</center>
<hr>
<p>
<!-- directory listing in drop-down list -->
Available directories:
<form action=actions.php method=post>

<!-- these values are passed hidden every time -->
<!-- a more optimal solution might be to place these in session
variables -->
<input type=hidden name=username value=<? echo $username; ?>>
<input type=hidden name=password value=<? echo $password; ?>>
<input type=hidden name=server value=<? echo $server; ?>>
<input type=hidden name=cdir value=<? echo $here; ?>>

<!-- action to take when THIS form is submitted -->
<input type=hidden name=action value=CWD>

<!-- dir listing begins; first item is for parent dir -->
<select name=rdir>
<option value=".."><parent directory></option>

<?

for ($x=0; $x<sizeof($dir_list); $x++)
{
echo "<option value=" . $dir_list[$x] . ">" . $dir_list[$x] . "</option>";

}
?>

</select>
<input type=submit value=Go>
</form>

<hr>

<!-- file listing begins -->

Available files:
<form action=actions.php method=post>

<!-- these values are passed hidden every time -->
<input type=hidden name=server value=<? echo $server; ?>>
<input type=hidden name=username value=<? echo $username; ?>>
<input type=hidden name=password value=<? echo $password; ?>>
<input type=hidden name=cdir value=<? echo $here; ?>>

<table border=0 width=100%>

<?

// display file listing with checkboxes and sizes
for ($y=0; $y<sizeof($files); $y++)
{
echo "<tr><td><input type=checkbox name=dfile[] value=" . $files[$y] .
">". $files[$y] . " <i>(" . $file_sizes[$y] . " bytes)</i><td>";
}

?>
</table>

<!-- actions for this form -->
<center>
<input type=submit name=action value=Delete>
<input type=submit name=action value=Download>
</center>
</form>
<p>

<hr>

<!-- file upload form -->
File upload:
<form enctype="multipart/form-data" action=actions.php method=post>

<!-- these values are passed hidden every time -->
<input type=hidden name=username value=<? echo $username; ?>>
<input type=hidden name=password value=<? echo $password; ?>>
<input type=hidden name=server value=<? echo $server; ?>>
<input type=hidden name=cdir value=<? echo $here; ?>>

<table>
<tr>
<td>
<!-- file selection box -->
<input type=file name=upfile>
</td>
</tr>
<tr>
<td>
<!-- action for this form -->
<input type=submit name=action value=Upload>
</td>
</tr>
</table>
</form>

<!-- code for include.php ends here -->

php技術(shù)PHP的FTP學(xué)習(xí)(二)[轉(zhuǎn)自奧索],轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 富婆夜店找黑人猛男BD在线 | 伊人久久大香线蕉综合电影 | 国产精自产拍久久久久久蜜 | 亚洲大片免费观看 | 性色欲情网站IWWW | 动漫H片在线观看播放免费 动漫H片在线播放免费高清 | 国产精品自在在线午夜蜜芽tv在线 | 国产精品亚洲第一区二区三区 | 亚洲精品97福利在线 | 天美传媒色情原创精品 | 一本之道高清在线观看免费 | 色AV色婷婷97人妻久久久 | 国产精品福利片 | 成年人视频在线免费 | 99久久久无码国产精品免费人妻 | 成人精品视频在线观看 | 西西人体大胆牲交PP6777 | 国产成人精品区在线观看 | 秋霞在线看片无码免费 | 国产精品亚洲国产三区 | 99久久人妻无码精品系列性欧美 | 在线观看国产精美视频 | 国语自产拍大学生在线观看 | 国产精品av免费观看 | 久久精品国产清白在天天线 | 色怕怕 | 好湿好滑好硬好爽好深视频 | 精品国产在天天线在线麻豆 | 国产区精品综合在线 | 國產麻豆AVMDXMDX | 乱亲女H秽乱长久久久 | 嗯啊插的好深啊使劲抽视频 | 美女脱得只剩皮肤 | 超碰v| 久久精品国产男包 | 精品一二三区久久AAA片 | 99riav9 精品香蕉免费大视频 | 欧美日韩高清一区 | 国产精品乱码色情一区二区视频 | 国内精品九九视频 | 久久久精品久久久久久 |