Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<?php
if (isset($_POST['upload']) && $_POST['upload'] == 1) {
// set up the variables
$ftp_server = "server_name_or_IP_address";
$ftp_user = "username";
$ftp_password = "password";
$destination_directory = "some/directory/from/default/ftp/directory";
$destination_file = "ftp_upload_test.gif";
// make sure FTP is enabled on the server
if (function_exists("ftp_connect"))
echo "FTP enabled on server...<br>\n";
else {
echo "FTP is not enabled on $ftp_server!";
exit;
}
// set up connection
$conn_id = ftp_connect($ftp_server);
if (!$conn_id) {
echo "Could not connect!";
exit;
}
else echo "Connected...<br>\n";
// log in
$login_result = ftp_login($conn_id, $ftp_user, $ftp_password);
if (!$login_result) {
echo "Could not log in!";
exit;
}
else echo "Logged in...<br>\n";
// set to passive mode
$set_passive = ftp_pasv($conn_id, true);
if (!$set_passive) {
echo "Could not set to passive mode!";
exit;
}
else echo "Connection is set to passive mode...<br>\n";
// set the timeout in seconds
$set_timeout = ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 300);
if (!$set_timeout) {
echo "Could not set the timeout!";
exit;
}
else echo "Set timeout...<br>\n";
// change directories
$change_dir = ftp_chdir($conn_id, $destination_directory);
if (!$change_dir) {
echo "Failed to change directory!";
exit;
}
else echo "Changed directory...<br>\n";
// upload the file
$source_path = $_FILES['source_file']['tmp_name'];
$upload = ftp_put($conn_id, $destination_file, $source_path, FTP_BINARY);
// check upload status
if (!$upload)
echo "FTP upload has failed!";
else
echo "Uploaded $source_path to $ftp_server as <b>$destination_file</b>";
// close the FTP stream
ftp_close($conn_id);
echo "\n<hr>\n";
}
?>
<form action="ftp_example.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="upload" value="1">
<b>GIF File to upload: </b><input type="file" name="source_file"><br>
<input type="submit" value=" Upload ">
</form>