/***********************************************
Upload file to FTP
***********************************************/
//FTP Connection Information
$ftp_server = '';
$ftp_user_name = '';
$ftp_user_pass = '';
//Keep track of success or failure
$bFTPSuccess = false;
//Move file to the upload directory
move_uploaded_file($_FILES["file"]["tmp_name"], $_g['ROOT_PATH']."upload/" . $_FILES["file"]["name"]);
//Open the file
$file = $_g['ROOT_PATH']."upload/" . $_FILES["file"]["name"];
$fp = fopen($file, 'r');
//Connect to the FTP
$conn_id = ftp_connect($ftp_server);
//Login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//If the file doesn't already exist on the FTP
if (ftp_size ($conn_id, $_FILES["file"]["name"]) == -1)
{
//Try to upload $file
if (ftp_fput($conn_id, $_FILES["file"]["name"], $fp, FTP_ASCII))
{
//echo "Successfully uploaded $file\n";
$bFTPSuccess = true;
}
else
{
die("There was a problem while uploading $file\n");
}
}
else
{
die("File already exists!");
}
//Close the FTP connection and the file
ftp_close($conn_id);
fclose($fp);
//Delete the file from the upload directory
unlink($file);
|