Hi,
I'm trying to upload files from a subdomain to the primary domain. So the upload form is on the domain admin.mySite.com and I'm trying to upload the files to www.mySite.com/files/
Here's my script.
<?php
if($_POST['submit']) {
$name = $_POST['name'];
$file = $_FILES["myFile"]["name"];
$ftp_server = "ftp.mySite.com";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = "ftp_username";
$ftp_user_pass = "ftp_password";
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!<br>\n";
echo "Attempted to connect to $ftp_server for user $ftp_user_name<br>\n";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name<br>\n";
}
$destination_file = "/public_html/files/" . $_FILES["myFile"]["name"];
$source_file = $_FILES["myFile"]["name"];
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII);
// check upload status
if (!$upload) {
echo "FTP upload has failed!<br>\n";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file<br>\n";
$sql = "INSERT INTO files (name, file) VALUES ('$name', '$file')";
$res = mysql_query($sql) or die(mysql_error());
echo "Your <b>File</b> has been added successfully!\n";
}
// close the FTP stream
ftp_close($conn_id);
}else {
echo "<form method=\"POST\" enctype=\"multipart/form-data\">\n";
echo "<table border=\"0\"><tr>\n<td>Name:</td>\n<td><input type=\"text\" name=\"name\">\n</tr><tr><td>File:</td>\n<td><input type=\"file\" name=\"myFile\"></td>\n</tr>\n<tr><td align=\"right\" colspan=\"2\"><input type=\"submit\" value\"Add File\" name=\"submit\">\n</td></tr>\n";
echo "</table></form>\n";
}
?>