I would like some help concerning how to upload a local file from an application to FTP using PHP code. I am an amateur programmer that can read very basic code structure. So please avoid using programming terms!
I am developing a simple Windows application (through visual programming). The app will upload a local file to my FTP server through a web site (e.g. http://www.mysite/folder/ftp.php). I am doing this in order to avoid including my FTP login details in the app's code.
I have found a PHP code that seems to work, but I do not understand how to include my local file's path in the code (e.g. C:\User\Desktop\myfile.txt
). I wish to use the following code, which I found pretty easy to understand. I just don't know how to specify the path of the local file as well as the path where this file will be uploaded. Finally, the local path will be specified in the link (eg http://www.mysite/folder/ftp.php?localpath=.....), so I think that I should use a $file=$_GET['file'];
instead of $file = ".....";
.
<?php
$ftp_server="";
$ftp_user_name="";
$ftp_user_pass="";
$file = "";//tobe uploaded
$remote_file = "";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
?>