ฟังก์ชันPHP FTP
บทนำ PHP FTP
ฟังก์ชัน FTP ช่วยให้ไคลเอ็นต์เข้าถึงไฟล์เซิร์ฟเวอร์ผ่าน File Transfer Protocol (FTP)
ฟังก์ชัน FTP ใช้เพื่อเปิด เข้าสู่ระบบ และปิดการเชื่อมต่อ ตลอดจนอัปโหลด ดาวน์โหลด เปลี่ยนชื่อ ลบ และรับข้อมูลเกี่ยวกับไฟล์จากเซิร์ฟเวอร์ไฟล์ ฟังก์ชัน FTP บางอย่างอาจไม่ทำงานได้กับทุกเซิร์ฟเวอร์หรือส่งกลับผลลัพธ์เดียวกัน ฟังก์ชัน FTP สามารถใช้ได้กับ PHP 3
หากคุณต้องการอ่านหรือเขียนไฟล์บนเซิร์ฟเวอร์ FTP เท่านั้น ให้พิจารณาใช้ ftp:// wrapper ที่มีฟังก์ชันระบบไฟล์ซึ่งมีอินเทอร์เฟซที่เรียบง่ายและใช้งานง่ายขึ้น
การติดตั้ง
เพื่อให้ฟังก์ชันเหล่านี้ทำงานได้ คุณต้องคอมไพล์ PHP ด้วย --enable-ftp
PHP เวอร์ชัน Windows มีการรองรับส่วนขยายนี้ในตัว
ฟังก์ชัน PHP FTP
Function | Description |
---|---|
ftp_alloc() | Allocates space for a file to be uploaded to the FTP server |
ftp_cdup() | Changes to the parent directory on the FTP server |
ftp_chdir() | Changes the current directory on the FTP server |
ftp_chmod() | Sets permissions on a file via FTP |
ftp_close() | Closes an FTP connection |
ftp_connect() | Opens an FTP connection |
ftp_delete() | Deletes a file on the FTP server |
ftp_exec() | Executes a command on the FTP server |
ftp_fget() | Downloads a file from the FTP server and saves it into an open local file |
ftp_fput() | Uploads from an open file and saves it to a file on the FTP server |
ftp_get() | Downloads a file from the FTP server |
ftp_get_option() | Returns runtime options of the FTP connection |
ftp_login() | Logs in to the FTP connection |
ftp_mdtm() | Returns the last modified time of a specified file |
ftp_mkdir() | Creates a new directory on the FTP server |
ftp_mlsd() | Returns the list of files in the specified directory |
ftp_nb_continue() | Continues retrieving/sending a file (non-blocking) |
ftp_nb_fget() | Downloads a file from the FTP server and saves it into an open file (non-blocking) |
ftp_nb_fput() | Uploads from an open file and saves it to a file on the FTP server (non-blocking) |
ftp_nb_get() | Downloads a file from the FTP server (non-blocking) |
ftp_nb_put() | Uploads a file to the FTP server (non-blocking) |
ftp_nlist() | Returns a list of files in the specified directory on the FTP server |
ftp_pasv() | Turns passive mode on or off |
ftp_put() | Uploads a file to the FTP server |
ftp_pwd() | Returns the current directory name |
ftp_quit() | Alias of ftp_close() |
ftp_raw() | Sends a raw command to the FTP server |
ftp_rawlist() | Returns a list of files with file information from a specified directory |
ftp_rename() | Renames a file or directory on the FTP server |
ftp_rmdir() | Deletes an empty directory on the FTP server |
ftp_set_option() | Sets runtime options for the FTP connection |
ftp_site() | Sends an FTP SITE command to the FTP server |
ftp_size() | Returns the size of the specified file |
ftp_ssl_connect() | Opens a secure SSL-FTP connection |
ftp_systype() | Returns the system type identifier of the FTP server |
PHP ค่าคงที่ FTP ที่กำหนดไว้ล่วงหน้า
Constant | Type | Description |
---|---|---|
FTP_ASCII | Integer | |
FTP_AUTOSEEK | Integer | |
FTP_AUTORESUME | Integer | |
FTP_BINARY | Integer | |
FTP_FAILED | Integer | Asynchronous transfer has failed |
FTP_FINISHED | Integer | Asynchronous transfer is completed |
FTP_IMAGE | Integer | Alias of FTP_BINARY |
FTP_MOREDATA | Integer | Asynchronous transfer is in progress |
FTP_TEXT | Integer | Alias of FTP_ASCII |
FTP_TIMEOUT_SEC | Integer | The timeout used for network operations |
FTP_USEPASVADDRESS | Boolean |