PHP ftp cdup

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : ftp_cdup() function

Description

The ftp_cdup() function is used to change the current directory to the parent directory.

Version

(PHP 4 and above)

Syntax

ftp_cdup(ftp_stream)

Parameters

Name

Description

Required /
Optional

Type

ftp_stream

The link identifier of the FTP connection.

Required

Resource

 

Return value

TRUE on success or FALSE on failure.

Value Type : Boolean

Example :

  1. $ftp_server="192.168.0.2";  

  2. $ftp_user_name="abc123";  

  3. $ftp_user_pass="abc123";  

  4. // set up basic connection  

  5. $conn_id = ftp_connect($ftp_server);  

  6. // login with username and password  

  7. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);  

  8. // change the current directory to html  

  9. ftp_chdir($conn_id, 'test');  

  10. echo ftp_pwd($conn_id); // /test  

  11. // return to the parent directory  

  12. if (ftp_cdup($conn_id)) {   

  13.   echo "
    cdup successful ";  

  14. } else {  

  15.   echo "cdup not successful ";  

  16. }  

  17. echo "
    ".ftp_pwd($conn_id); // /  

  18. ftp_close($conn_id);  

  19. ?>