<?php // variables $ftpServer = "hostAddress"; $ftpUser = "userID"; $ftpPass = "password"; $finalDir = '/httpdocs/km/tmp/'; $finalFile = $finalDir . $_FILES['userfile']['name']; $sourceFile = $_FILES['source_file']['tmp_name']; // Connect and echo result $ftpConn = ftp_connect("$ftpServer"); $ftpResult = ftp_login($ftpConn, $ftpUser, $ftpPass); ftp_pasv($ftpConn, true); if ((!$ftpConn) || (!$ftpResult)) echo "Connection failed<br><br>"; else echo "Connection succeeded<br><br>"; // upload the file $ftpUpload = ftp_put($ftpConn, $finalFile, $sourceFile, FTP_BINARY); // check upload status if (!$ftpUpload) echo "FTP upload has failed!"; else echo "Uploaded $sourceFile to $ftpServer as $finalFile"; // close the FTP stream ftp_close($ftpConn); ?>