What potential issue could arise when using the ftp_chdir function in PHP?

When using the ftp_chdir function in PHP, a potential issue that could arise is that the function may fail if the directory path provided is incorrect or inaccessible. To solve this issue, you should always check the return value of the ftp_chdir function to ensure that the directory change was successful before proceeding with any further operations.

// Connect to FTP server
$ftp = ftp_connect('ftp.example.com');
$login = ftp_login($ftp, 'username', 'password');

// Change directory
if (ftp_chdir($ftp, '/path/to/directory')) {
    echo 'Directory changed successfully.';
    // Further operations can be performed here
} else {
    echo 'Failed to change directory.';
}

// Close FTP connection
ftp_close($ftp);