Okay, let’s take a look at file upload using the ftp function that comes with PHP. To upload files, we will use ftp_put to transfer the files to the server. Below are two simple examples of uploading.
Okay, let’s take a look at file upload using the ftp function that comes with PHP. To upload files, we will use ftp_put to transfer the files. There are two simple examples of uploading to the server.
$file = 'somefile.txt';
$remote_file = 'readme.txt';
// Connect to FTP server
$conn_id = ftp_connect($ftp_server);
//Log in using username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//Upload file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "Successfully uploaded $file file n";
} else {
echo "Failed to upload $file filen";
}
// Close ftp connection
ftp_close($conn_id);
?>
//Open the file to be uploaded
$file = 'demofile.txt';
$fp = fopen($file, 'r');
// Connect to FTP server www.111cn.cn/
$conn_id = ftp_connect($ftp_server);
//Log in to the FTP server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//Upload file
if(ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
echo "Upload $file file successfully";
} else {
echo "Failed to upload $file file";
}
//Close FTP connection
ftp_close($conn_id);
//Close the open upload file
fclose($fp);
?>
Please indicate www.111cn.cn/phper/php.html