Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm ftp_fget() trong PHP


Hàm ftp_fget() tải xuống tập tin từ máy chủ FTP và lưu vào một tập tin cục bộ đang mở (file handle).

Cú pháp

ftp_fget($conn, $open_file, $server_file, $mode, $startpos)

Tham số

  • conn – Kết nối FTP.

  • open_file – Con trỏ tập tin cục bộ mở để ghi.

  • server_file – Tập tin trên server cần tải xuống.

  • mode – Chế độ truyền.

  • startpos – Vị trí bắt đầu tải xuống (từ PHP 4.3.0).

Giá trị trả về

Hàm trả về TRUE nếu thành công, FALSE nếu thất bại.

Ví dụ

<?php
$ftp_server = "192.168.0.4";
$ftp_user = "amit";
$ftp_pass = "tywg61gh";
$con = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($con, $ftp_user, $ftp_pass);
$my_serverfile = "demo.txt";
$local_file = "new.txt";
$file_pointer = fopen($local_file, "w");
if (ftp_fget($con, $file_pointer, $my_serverfile, FTP_ASCII, 0)) {
    echo "Written to $local_file!";
} else {
    echo "Error in downloading the $my_serverfile!";
}
ftp_close($con);
fclose($file_pointer);
?>