array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.ftp-put.php', 1 => 'ftp_put', ), 'up' => array ( 0 => 'ref.ftp.php', 1 => 'FTP 函数', ), 'prev' => array ( 0 => 'function.ftp-pasv.php', 1 => 'ftp_pasv', ), 'next' => array ( 0 => 'function.ftp-pwd.php', 1 => 'ftp_pwd', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/ftp/functions/ftp-put.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
ftp_put — 上传文件到 FTP 服务器
$ftp
,$remote_filename
,$local_filename
,$mode
= FTP_BINARY
,$offset
= 0ftp_put() 函数用来上传指定的本地文件到 FTP 服务器。
ftp
FTP\Connection 实例。
remote_filename
远程文件路径。
local_filename
本地文件路径。
mode
传送模式,只能为 FTP_ASCII
(文本模式)或 FTP_BINARY
(二进制模式)。
offset
指定开始上传的位置,一般用来文件续传。
版本 | 说明 |
---|---|
8.1.0 |
现在 ftp 参数接受 FTP\Connection
实例,之前接受 resource。
|
7.3.0 |
mode 参数为可选,之前版本中为必选。
|
示例 #1 ftp_put() 实例
<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';
// set up basic connection
$ftp = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($ftp, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($ftp);
?>