In order to use FTP functions with your PHP configuration, you should
add the
--enable-ftp
option when
installing PHP 4 or greater or
--with-ftp
when using PHP 3.
PHP
的 Windows
版本已经内置该扩展模块的支持。无需加载任何附加扩展库即可使用这些函数。
本扩展模块在
php.ini
中未定义任何配置选项。
以下常量由本扩展模块定义,因此只有在本扩展模块被编译到
PHP 中,或者在运行时被动态加载后才有效。
下列变量在 PHP 4.3.0 以后版本中被加入。
例子 1. FTP 例子
<?php
// 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
);
// check connection
if ((!
$conn_id
) || (!
$login_result
)) {
echo
"FTP connection has failed!"
;
echo
"Attempted to connect to $ftp_server for user $ftp_user_name"
;
exit;
} else {
echo
"Connected to $ftp_server, for user $ftp_user_name"
;
}
// upload the file
$upload
=
ftp_put
(
$conn_id
,
$destination_file
,
$source_file
,
FTP_BINARY
);
// check upload status
if (!
$upload
) {
echo
"FTP upload has failed!"
;
} else {
echo
"Uploaded $source_file to $ftp_server as $destination_file"
;
}
// close the FTP stream
ftp_close
(
$conn_id
);
?>
|
|