PHP ftp_chdir() Function

Definition and Usage

The ftp_chdir() function changes the current directory on the FTP server.

If successful, returns true. Otherwise, returns false. If the directory change fails, PHP will also issue a warning.

Syntax

ftp_chdir(ftp_connection,directory)
Parameter Description
ftp_connection Required. Specifies the FTP connection to be used (the identifier for the FTP connection).
directory Required. Specifies the directory to be switched to.

Example

<?php
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","ert456");
//Output current directory
echo "Dir: ".ftp_pwd($conn);
echo "<br />";
//Change to images directory
ftp_chdir($conn,"images");
echo "Dir: ".ftp_pwd($conn);
ftp_close($ftp_server);
?>

Output:

Dir: /
Dir: /images