ftp_chdir

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_chdir在 FTP 服务器上改变当前目录

说明

ftp_chdir(FTP\Connection $ftp, string $directory): bool

将当前目录切换为指定的目录。

参数

ftp

FTP\Connection 实例。

directory

目标目录。

返回值

成功时返回 true, 或者在失败时返回 false。如果切换目录失败,PHP 还会发出一条警告。

更新日志

版本 说明
8.1.0 现在 ftp 参数接受 FTP\Connection 实例,之前接受 资源(resource)

范例

示例 #1 ftp_chdir() 例子

<?php

// 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);

// check connection
if ((!$ftp) || (!$login_result)) {
die(
"FTP connection has failed !");
}

echo
"Current directory: " . ftp_pwd($ftp) . "\n";

// try to change the directory to somedir
if (ftp_chdir($ftp, "somedir")) {
echo
"Current directory is now: " . ftp_pwd($ftp) . "\n";
} else {
echo
"Couldn't change directory\n";
}

// close the connection
ftp_close($ftp);
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top