Home  >  Article  >  Backend Development  >  php ftp_put upload file tutorial_PHP tutorial

php ftp_put upload file tutorial_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:06:581036browse

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630481.htmlTechArticleOkay let’s take a look at file upload using the ftp function that comes with PHP. We will use it to upload files. Go to ftp_put to transfer files to the server. There are two simple examples of uploading below. Okay, here we go...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn