This article mainly introduces the usage of ftp_chdir and ftp_cdup functions in php, describes the FTP directory operation skills in PHP in the form of examples, and has some reference value, for more information about ftp_chdir and ftp_cdup functions in php, see the example below. Share it with you for your reference. The usage is as follows:
Ftp_chdir () function
If the switch succeeds, true is returned. otherwise, false is returned. if the switch fails, php will issue a warning.
Syntax: ftp_chdir (ftp_connection, directory)
Parameters |
Description |
Ftp_connection |
Required. specifies the ftp connection to be used, the identifier of the ftp connection. |
Directory |
Required. specifies the directory to switch. |
The code is as follows:
// Set the basic connection
$ Conn_id = ftp_connect ($ ftp_server );
// Log on to the ftp server with the specified username and password
$ Login_result = ftp_login ($ conn_id, $ ftp_user_name, $ ftp_user_pass );
// Check whether the connection is successful
If ((! $ Conn_id) | (! $ Login_result ))
{
Die ("ftp connection has failed! ");
}
Echo "current directory:", ftp_pwd ($ conn_id), "n ";
// Switch the Directory
If (@ ftp_chdir ($ conn_id, "somedir "))
{
Echo "current directory is now:", ftp_pwd ($ conn_id), "n ";
}
Else
{
Echo "couldn't change directoryn ";
}
Ftp_cdup ($ dir); // you can call this operation to switch directories.
/*
The ftp_cdup () function changes the current directory to the parent directory on the ftp server.
// If successful, true is returned. Otherwise, false is returned.
// Syntax
Ftp_cdup (ftp_connection)
I hope this article will help you with PHP programming.