您的位置:首页网页设计PHP实例 → PHP的FTP学习四 

PHP的FTP学习四 

时间:2004/11/7 3:26:00来源:本站整理作者:蓝点我要评论(0)

By Vikram Vaswani

Melonfire

November 07, 2000

以下是代码列表:

--------------------------------------------------------------------------------

































































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
{

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
{

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
{

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:









>

>

>

>




























Available files:







>

>

>

>










// display file listing with checkboxes and sizes

for ($y=0; $y
{

echo "
". $files[$y] . " (" . $file_sizes[$y] . " bytes)";

}



?>









   


















File upload:







>

>

>

>






































相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 我的php文件怎么打开_php运算符怎么写 php 如何生成静态页面的函数PHP生成图片缩略图PHP session常见问题集锦及解决办法PHP实现同步远程Mysql

人气排行 DEDE在文章列表文章没有缩略图的不显示图片php+mysq修改用户密码我的php文件怎么打开_如何打开php文件的办法FCKeditor的配置和使用方法使用dedecms建站教程PHP+Ajax实现分页技术图片存储与浏览一例Linux+Apache+PHP+MySQLPHP生成图片缩略图