I try to write php script for upload or download using ftp. Below the script
PHP Code:
$ftp_server = "localhost"; $ftp_user_name = "host"; $ftp_user_pass = "password";
$destination_file = "/ftp_server/sale.jpg"; //ftp server $source_file = "D:/sale.jpg"; //local machine
$conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
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"; }
ftp_close($conn_id);
What I want is when I open the script using browser, it will automatic upload or download file from server to my computer. And I put the script into another server that different with my computer.
But I can't do that because the script will read the path for computer that use as a php server not local machine that I use
Is it possible to create automatic script just with run the script without click browse button to upload or save as to download? If yes how can I do that? Thanks
|