PHP ftp_chdir()Functions
Complete PHP FTP Reference
Definition and Usage
The ftp_chdir() function changes the current directory on the FTP server to the specified directory.
If successful, the function returns TRUE. If it fails, it returns FALSE and a warning.
Syntax
ftp_chdir(ftp_connection,directory)
| Parameters | Description |
|---|---|
| ftp_connection | Required. Specifies the FTP connection to use. |
| directory | Required. Specifies the directory to switch to. |
Examples
<?php
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","ert456");
//Outputs the current directory
echo "Dir: ".ftp_pwd($conn);
echo "<br />";
//Change to the images directory
ftp_chdir($conn,"images");
echo "Dir: ".ftp_pwd($conn);
ftp_close($ftp_server);
?>
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","ert456");
//Outputs the current directory
echo "Dir: ".ftp_pwd($conn);
echo "<br />";
//Change to the images directory
ftp_chdir($conn,"images");
echo "Dir: ".ftp_pwd($conn);
ftp_close($ftp_server);
?>
The code above will output:
Dir: /
Dir: /images
Dir: /images
Complete PHP FTP Reference Other Extensions