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]); }
// 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); }
/* 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, ".");
/* 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. */