w3resource

PHP: ftp_chdir() function

Description

The ftp_chdir() function is used to change the current directory to a specified directory on an FTP server.

Version:

(PHP 4 and above)

Syntax:

ftp_chdir(ftp_connection, change_directory)

Parameters:

Name Description Required /
Optional
Type
ftp_connection The link identifier of the FTP connection. Required Resource
change_directory The target directory. Required String

Return value:

TRUE on success or FALSE on failure.

Value Type: Boolean

Example:

<?php
$ftp_server="192.168.0.2";
$ftp_user_name="abc123";
$ftp_user_pass="abc123";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// change the current directory to test
if (!ftp_chdir($conn_id, 'test'))
{
echo "chdir not successful"; // /test
}
else
echo "chidir successful. Directory changed to :".ftp_pwd($conn_id); // /test
ftp_close($conn_id);
?>

See also

PHP Function Reference

Previous: ftp_cdup
Next: ftp_chmod



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/ftp_chdir.php