(PHP 4, PHP 5, PHP 7, PHP 8)
ftp_put — 上传文件到 FTP 服务器
$ftp_stream,$remote_file,$local_file,$mode = FTP_BINARY,$startpos = 0ftp_put() 函数用来上传指定的本地文件到 FTP 服务器。
ftp_streamFTP 连接资源。
remote_file远程文件路径。
local_file本地文件路径。
mode
传送模式,只能为 FTP_ASCII(文本模式)或 FTP_BINARY(二进制模式)。
startpos指定开始上传的位置,一般用来文件续传。
成功时返回 true, 或者在失败时返回 false。
| 版本 | 说明 |
|---|---|
| 7.3.0 |
mode 参数为可选,之前版本中为必选。
|
示例 #1 ftp_put() 实例
<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $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($conn_id);
?>