by Vikram Vaswani
Melonfire
November 07, 2000
The following is a list of codes:
--------------------------------------------------------------------------------
<!--code for index.html begins-->
<basefont face=arial>
<!--code for index.html ends-->
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
<!--code for actions.php begins-->
It is meant a for illustrative purposes and isn't 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-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
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 being 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>
<!--code for actions.php ends-->
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
<!--code for include.php begins-->
?
Get Current Location
$here = Ftp_pwd ($result);
/*
Since Ftp_size () is quite slow, especially when working
On ' an ' array containing all of the files in a directory,
This section performs a ftp_size () on "All" the files in the current
Directory and creates three arrays.
*/
<!--header-where am I? -->
<center>
You are currently working in <B><? echo $here;?></b>
<br>
<!--status message for upload function-->
? echo $status;?>
</center>
<p>
<!--directory listing in Drop-down list-->
Available Directories:
<form action=actions.php method=post>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.