选择显示字体大小

php的ftp学习(四)

by vikram vaswani
melonfire
november 07, 2000
以下是代码列表:
--------------------------------------------------------------------------------
<!-- 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 &#36;server, &#36;username, &#36;password;
&#36;conn = ftp_connect(&#36;server);
ftp_login(&#36;conn, &#36;username, &#36;password);
return &#36;conn;
}


// main program begins

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


// connect
&#36;result = connect();

// action: change directory
if (&#36;action == "cwd")
{

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

// change to requested directory
ftp_chdir(&#36;result, &#36;path);

}

// action: delete file(s)
else if (&#36;action == "delete")
{

ftp_chdir(&#36;result, &#36;cdir);

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

}
// action: download files
else if (&#36;action == "download")
{

ftp_chdir(&#36;result, &#36;cdir);

// download selected files
// important: you should specify a different download location here!!
for (&#36;x=0; &#36;x<sizeof(&#36;dfile); &#36;x++)
{
ftp_get(&#36;result, &#36;dfile[&#36;x], &#36;dfile[&#36;x], ftp_binary);
}

}
// action: upload file
else if (&#36;action == "upload")
{

ftp_chdir(&#36;result, &#36;cdir);

// put file

/*
a better idea would be to use
&#36;res_code = ftp_put(&#36;result, &#36;http_post_files["upfile"]["name"],
&#36;http_post_files["upfile"]["tmp_name"], ftp_binary);
as it offers greater security
*/
&#36;res_code = ftp_put(&#36;result, &#36;upfile_name, &#36;upfile, ftp_binary);


// check status and display
if (&#36;res_code == 1)
{
&#36;status = "upload successful!";
}
else
{
&#36;status = "upload error!";
}

}

// create file list
&#36;filelist = ftp_nlist(&#36;result, ".");

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

// close connection
ftp_quit(&#36;result);

}
?>

</body>
</html>

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

<?

// get current location
&#36;here = ftp_pwd(&#36;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
&#36;files = array();

// array for directories
&#36;dirs = array();

// array for file sizes
&#36;file_sizes = array();

// counters
&#36;file_list_counter = 0;
&#36;dir_list_counter = 0;

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

?>

<!-- header - where am i? -->
<center>
you are currently working in <b><? echo &#36;here; ?></b>
<br>
<!-- status message for upload function -->
<? echo &#36;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 &#36;username; ?>>
<input type=hidden name=password value=<? echo &#36;password; ?>>
<input type=hidden name=server value=<? echo &#36;server; ?>>
<input type=hidden name=cdir value=<? echo &#36;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 (&#36;x=0; &#36;x<sizeof(&#36;dir_list); &#36;x++)
{
echo "<option value=" . &#36;dir_list[&#36;x] . ">" . &#36;dir_list[&#36;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 &#36;server; ?>>
<input type=hidden name=username value=<? echo &#36;username; ?>>
<input type=hidden name=password value=<? echo &#36;password; ?>>
<input type=hidden name=cdir value=<? echo &#36;here; ?>>

<table border=0 width=100%>

<?

// display file listing with checkboxes and sizes
for (&#36;y=0; &#36;y<sizeof(&#36;files); &#36;y++)
{
echo "<tr><td><input type=checkbox name=dfile[] value=" . &#36;files[&#36;y] .
">". &#36;files[&#36;y] . " <i>(" . &#36;file_sizes[&#36;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 &#36;username; ?>>
<input type=hidden name=password value=<? echo &#36;password; ?>>
<input type=hidden name=server value=<? echo &#36;server; ?>>
<input type=hidden name=cdir value=<? echo &#36;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 -->


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons