PHP FTP Learning (iv) _php tutorial

Source: Internet
Author: User
by Vikram Vaswani
Melonfire
November 07, 2000
The following is a list of codes:
--------------------------------------------------------------------------------
















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








/*
--------------------------------------------------------------------------------
DISCLAIMER:

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

It is meant-only for illustrative purposes and are not meant for production environments. No warranties of any kind is 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 $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 is 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 a 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 is currently working in








Available Directories:






Available files:






File Upload:



http://www.bkjia.com/PHPjc/316065.html www.bkjia.com true http://www.bkjia.com/PHPjc/316065.html techarticle by Vikram Vaswani melonfire November 07, 2000 the following is a list of codes:----------------------------------------------------------- ---------------------!--code for index.html begin ...

  • Related Article

    Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.