Usage of ftp_chdir and ftp_cdup functions in php

Source: Internet
Author: User
Tags ftp connection
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.