What function in PHP can be used to change directories in FTP upload instead of chdir?

To change directories in FTP upload in PHP without using the chdir function, you can use the ftp_chdir function. This function allows you to change directories on the FTP server without having to navigate through the local file system. By using ftp_chdir, you can easily switch directories during an FTP upload process.

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

// Change directory on FTP server
ftp_chdir($ftp, '/path/to/directory');

// Upload file to new directory
ftp_put($ftp, 'remote_file.txt', 'local_file.txt', FTP_BINARY);

// Close FTP connection
ftp_close($ftp);