I have created a form. In this form you can upload a file. The file has to be uploaded to a remote FTP server. The connection to the FTP remote server works. However it does not upload the file. I do not know how to solve this problem. I get the following message when I want to upload: "FTP upload has failed!". This is a message I programmed to show when the upload does not work. No errors.
My PHP code (based on a previous Stack Overflow question):
<?php
if ( empty( $_FILES['file'] ) ) {
return;
}
$ftp_server = "ftp.myserver.nl";
$ftp_user_name = "myusername";
$ftp_user_pass = "mypass";
$destination_file = "/public_html/wp/wp-content/plugins/AbonneerProgrammas/Albums";
$source_file = $_FILES['file']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// 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!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
My HTML code (based on a previous Stack Overflow question):
<html>
<body>
<form action="" enctype="multipart/form-data" method="post">
<input name="file" type="file"/>
<br>
<input name="submit" type="submit" value="Upload uw album" />
</form>
</body>
</html>
I expect that when I submit the form, the file gets transferred to the following path: /public_html/wp/wp-content/plugins/AbonneerProgrammas/Albums. Hopefully you guys can help me out. I am programming in WordPress using the plugin PHPCodeSnippets.
print_r($_FILES); exit();and see if if there are posted files in this array. - Jamie_D