Most of the data are user defined, I successfully connect to my server but I can't seem to get the file to upload,
the $ftp_source_file variable echoes an empty string...
What I want to achieve is to be able to upload a file via ftp in the $ftp_upload_directory, and I need the file ($ftp_destination_file) to be with its original filename. (like, if testimage.jpg was uploaded, then it remains testimage.jpg on the server as well.)
HTML submission form:
PHP upload script "getfile.php"<html>
<body>
<form action="getfile.php" method="post" enctype="multipart/form-data">
Server:
<input name="ftp_server" type="text" id="ftp_server" />
username:
<input name="ftp_username" type="text" id="ftp_username" />
Password: <input name="ftp_password" type="password" id="ftp_password" />
<br>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Get this file: <input name="ftp_source_file" type="file" id="ftp_source_file" />
<!--/upload-->
<input type="submit" value="UPLOAD" />
</form>
</body>
</html>
<?php
$ftp_server="$_POST[ftp_server]";
$ftp_username="$_POST[ftp_username]";
$ftp_password="$_POST[ftp_password]";
$ftp_upload_directory="/home/base/public_html/test/ftp/";
$ftp_source_file="$_POST[ftp_source_file]";
$ftp_destination_file=$ftp_source_file;
$ftp_connection_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($ftp_connection_id, $ftp_username, $ftp_password);
// check connection
if ((!$ftp_connection_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftpserver for user $ftp_username";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_username : trying to upload $ftp_source_file<br>";
}
// upload the file
$ftp_do_upload = ftp_put($ftp_connection_id, $ftp_upload_directory . $ftp_destination_file, $ftp_source_file, FTP_BINARY);
// check upload status
if (!$ftp_do_upload) {
echo "FTP upload has failed to: $ftp_upload_directory . $ftp_destination_file";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($ftp_connection_id);
?>