So I have setup an FTP script to allow a user to upload a file via a web browser to my server. It all works and the file appears on the screen and in the directory on the server the only problem is that there isn't any actual data in the file. It appears to be there, but when you open it it's just a 0kb file with no text or anything.
Any ideas? Here is my code...Thanks!
>if ($_POST["action"] == "add") {
// Get all the POST data
$ftp_server='ftp.jonkinney.com';//serverip
$conn_id = ftp_connect($ftp_server);
// login with username and password
$user="username";
$passwd="password";
$login_result = ftp_login($conn_id, $user, $passwd);
// check connection
if ((!$conn_id) || (!$login_result)) {
header("Location: http://www.jonkinney.com/stichabrossite/managedownloads.php?error=FTP connection has failed!<br />Attempted to connect to $ftp_server for user $ftp_user_name");
die;
} else {
//directory switching
if (downloadtype_id == "1"){
$directory = "mixes";
} else {
$directory = "files"; }
ftp_chdir($conn_id, "public_html/stichabrossite/downloads/$artistname/$directory");
$destination_file= "$filename";
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
header("Location: http://www.jonkinney.com/stichabrossite/managedownloads.php?error=Upload has failed!");
} else {
mysql_query("INSERT INTO Downloads (Title, Description, DownloadType_id , Filename, Artist)
VALUES ('$title', '$description', '$downloadtype_id', '$filename', '$artistname')", $connection);
header("Location: http://www.jonkinney.com/stichabrossite/managedownloads.php?error=Uploaded local file to $ftp_server as $destination_file");
}
// close the FTP stream
ftp_close($conn_id);
}