首页 >

PHP的FTP学习(四)

后端开发|php教程PHP的FTP学习(四)
PHP,FTP,学习,四,Vikram,Vaswani,Melonfire,November,2000,以下,是,代
后端开发-php教程
By Vikram Vaswani
Melonfire
November 07, 2000
以下是代码列表:
——————————————————————————–

博客 源码92 tx,vscode 新标签页打开,pd装ubuntu,tomcat做win服务,社交平台爬虫,php当前时间代码,上饶运营seo多少钱,html5 手机网站 模版,订单html模板lzw
asp手机文章类网站源码,vscode更换护眼颜色,ubuntu写镜像,tomcat优化可调参数,爬虫上树,php 请求 响应,放心网站seo效果好,破解授权网站源码,登录界面 css模板lzw
城市源码下载,vscode盘符前ps,优化ubuntu系统,tomcat发布网站应用,操作sqlite3的类,机顶盒数据配置接口爬虫站点,php正则的或,闽清企业seo是什么,流媒体网站 源码,免费动画模板下载 迅雷下载 迅雷下载地址lzw

Server
User
Password



——————————————————————————–
——————————————————————————–


<?
/*
——————————————————————————–
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);

}
?>



——————————————————————————–
——————————————————————————–

<? // 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++;
}
}

?>


You are currently working in




Available directories:


<!– a more optimal solution might be to place these in session
variables –>
<input type=hidden name=username value=>
<input type=hidden name=password value=>
<input type=hidden name=server value=>
<input type=hidden name=cdir value=>



<? for ($x=0; $x<sizeof($dir_list); $x++)
{
echo “” . $dir_list[$x] . “”;

}
?>



Available files:


<input type=hidden name=server value=>
<input type=hidden name=username value=>
<input type=hidden name=password value=>
<input type=hidden name=cdir value=>

<? // display file listing with checkboxes and sizes
for ($y=0; $y<sizeof($files); $y++)
{
echo “

<input type=checkbox name=dfile[] value=" . $files[$y] .
“>”. $files[$y] . ” (” . $file_sizes[$y] . ” bytes)

“;
}

?>





File upload:


<input type=hidden name=username value=>
<input type=hidden name=password value=>
<input type=hidden name=server value=>
<input type=hidden name=cdir value=>



http://www.liuzhongwei.com/PHPjc/316065.htmlwww.liuzhongwei.comtruehttp://www.liuzhongwei.com/PHPjc/316065.htmlTechArticleBy Vikram Vaswani Melonfire November 07, 2000 以下是代码列表: ——————————————————————————– !– code for index.html begin…

PHP的FTP学习(四)
  • PHP的FTP学习(一)[转自奥索]
  • PHP的FTP学习(一)[转自奥索] | PHP的FTP学习(一)[转自奥索] ...

    PHP的FTP学习(四)
  • PHP的FTP学习(一)[转自奥索]
  • PHP的FTP学习(一)[转自奥索] | PHP的FTP学习(一)[转自奥索] ...

    PHP的FTP学习(四)
  • PHP的FTP学习(四)
  • PHP的FTP学习(四) | PHP的FTP学习(四) ...