(PHP 4, PHP 5)
ftp_fput — 上传一个已经打开的文件到 FTP 服务器
$ftp_stream
, string $remote_file
, resource $handle
, int $mode
[, int $startpos
] )
ftp_fput() 函数用来上传一个在已经打开的文件中的数据到 FTP 服务器,参数
handle
为所打开文件的句柄。参数
remote_file
为上传到服务器上的文件名。传输模式参数
mode
只能为 (文本模式) FTP_ASCII
或
(二进制模式) FTP_BINARY
其中的一个。
Example #1 ftp_fput() example
<?php
// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');
// connect to the server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to upload the file
if(ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);
?>
Note:
参数
startpos
只适用于 4.3.0 以上版本。
成功时返回 TRUE
, 或者在失败时返回 FALSE
.
参见 ftp_put(), ftp_nb_fput() 和 ftp_nb_put()。
ftp_stream
The link identifier of the FTP connection.
remote_file
The remote file path.
handle
An open file pointer on the local file. Reading stops at end of file.
mode
The transfer mode. Must be either FTP_ASCII
or
FTP_BINARY
.
startpos
The position in the remote file to start uploading to.
成功时返回 TRUE
, 或者在失败时返回 FALSE
.
Example #2 ftp_fput() example
<?php
// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');
// 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);
// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);
?>
版本 | 说明 |
---|---|
4.3.0 |
startpos was added.
|