Hướng dẫn how to read file from ftp in php? - cách đọc tệp từ ftp trong php?

Tôi có hai máy chủ. Tôi đã có một tệp .txt trong tệp tôi đang kết nối.

Tôi cần lấy nội dung tệp .txt và đặt chúng vào biến $. Đây là mã của tôi không hoạt động:

$ftp_server = $_POST["site"];
$path = $_POST["path"];
$ftp_user_name = $_POST["username"];
$ftp_user_pass = $_POST["pass"];

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

$remote_filename =
    "/" . $_POST["path"] . "/" . "#" . $result["id"]
    . " - " .    $result["LastName"] . ", " . $result["FirstName"]
    . "/" . $_POST["title"] . ".txt";
ftp_get($conn_id, $content, $remote_filename, FTP_ASCII);

Mã này kết nối với FTP và tôi đã sử dụng ftp_get để sao chép từ một tệp văn bản sang một biến gọi là $content. Tôi biết một biến không thuộc về tham số này, nhưng tôi được bán ngay bây giờ. Tôi không biết làm thế nào để đọc tệp .txt này.

Có cách nào để làm điều này với các chức năng PHP FTP không?

Bây giờ, khi tôi thử điều này:

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');

Nó gây ra lỗi:

Cảnh báo: Fopen (FTP: /// 101NoteBook sao lưu: 22-08-2013/#11-Cappucci, Ryan/Queen.txt) [function.fopen] 08-2013/: Không phải là một tệp thông thường trong /home/content/34/11614434/html/adminpdo.php trên dòng 269

Tại sao tôi nhận được lỗi này?

Cảm ơn một lần nữa

(Php 4, Php 5, Php 7, Php 8)

FTP_GET - Tải xuống tệp từ máy chủ FTPDownloads a file from the FTP server

Sự mô tả

ftp_get (& nbsp; & nbsp; & nbsp; & nbsp; ftp \ Connection ________ 5, & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; int

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
0 = 0): bool(
    FTP\Connection $ftp,
    string $local_filename,
    string $remote_filename,
    int $mode = FTP_BINARY,
    int
$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
0 = 0

): bool

Thông số

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
1

Một thể hiện kết nối ftp \.FTP\Connection instance.

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
2

Đường dẫn tệp cục bộ (sẽ được ghi đè nếu tệp đã tồn tại).

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
3

Đường dẫn tệp từ xa.

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
4

Chế độ chuyển. Phải là

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
5 hoặc FTP_BINARY.
$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
5
or FTP_BINARY.

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
7

Vị trí trong tệp từ xa để bắt đầu tải xuống từ.

Trả về giá trị

Trả về

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
8 khi thành công hoặc
$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
9 về thất bại.
$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
8
on success or
$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
9
on failure.

Thay đổi

Phiên bảnSự mô tả
8.1.0 ftp_get (& nbsp; & nbsp; & nbsp; & nbsp; ftp \ Connection ________ 5, & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; int
$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
0 = 0): boolFTP\Connection instance now; previously, a resource was expected.
7.3.0 Thông số

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file'); 1

Một thể hiện kết nối ftp \.ftp_get() example

$2

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file'); 2

  • Đường dẫn tệp cục bộ (sẽ được ghi đè nếu tệp đã tồn tại).
  • $fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
    
    3
  • Đường dẫn tệp từ xa.
  • $fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
    
    4

Chế độ chuyển. Phải là

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
5 hoặc FTP_BINARY.

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
7

$3

$4

$5

$6

$7

$8

$9

ftp_get0

Vị trí trong tệp từ xa để bắt đầu tải xuống từ.

Trả về giá trị

ftp_get1

ftp_get2

ftp_get3

ftp_get0

Trả về

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
8 khi thành công hoặc
$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
9 về thất bại.

Thay đổi

ftp_get5

Phiên bản

Tham số

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
1 mong đợi một thể hiện kết nối FTP \ ngay bây giờ; Trước đây, một tài nguyên đã được dự kiến.

ftp_get6

Tham số

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
4 hiện là tùy chọn. Trước đây nó đã được bắt buộc.

14 năm trước

ftp_get7

ftp_get8

ftp_get9

$content0

Danny tại Ingeniarte dot com ¶

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
7

$content1

$content2

$content3

$content4

Vị trí trong tệp từ xa để bắt đầu tải xuống từ.

14 năm trước

$content5

$content6

$content7

Danny tại Ingeniarte dot com ¶

4 năm trước

$content8

Scott Dot Chu tại Udngroup Dot Com ¶

Trả về giá trị

$content9

$ftp0

ftp_get0

Phiên bản

Tham số

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
1 mong đợi một thể hiện kết nối FTP \ ngay bây giờ; Trước đây, một tài nguyên đã được dự kiến.

$ftp2

Tham số

$fileContents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');
4 hiện là tùy chọn. Trước đây nó đã được bắt buộc.

Ví dụ

$ftp3

$ftp4

$ftp5

$ftp6

$ftp7

$ftp8

$ftp9

ftp_get0

Corey-Holzer tại NYC Dot Rr dot com

18 năm trước

$local_filename1

thivierr tại telus dot net ¶

19 năm trước

$local_filename2

$local_filename3

$local_filename4

ftp_get0

Giáo xứ Ben ¶

10 năm trước

$local_filename6

$local_filename7

ftp_get0

Apurvavora19 tại gmail dot com ¶

4 năm trước

$local_filename9

$remote_filename0

$remote_filename1

$remote_filename2

ftp_get0

Scott Dot Chu tại Udngroup Dot Com ¶

6 năm trước

$remote_filename4

$remote_filename5

$remote_filename6

ftp_get0

w dot danford tại điện tử-software dot com ¶

14 năm trước

$remote_filename8

Danny tại Ingeniarte dot com ¶

11 năm trước

$remote_filename9

$mode0

ftp_get0

Làm thế nào để đọc các tệp từ FTP trong PHP?

File_Get_Contents là giải pháp dễ nhất: $ nội dung = file_get_contents ('ftp: // tên người dùng: pa‌ ssword@hostname/path/to/file');$contents = file_get_contents('ftp://username:pa‌​ssword@hostname/path/to/file');

Php ftp có nghĩa là gì?

PHP FTP Giới thiệu Các chức năng FTP cung cấp quyền truy cập máy khách vào máy chủ tệp thông qua Giao thức truyền tệp (FTP).Các chức năng FTP được sử dụng để mở, đăng nhập và kết nối gần, cũng như tải lên, tải xuống, đổi tên, xóa và nhận thông tin về các tệp từ các máy chủ tệp.File Transfer Protocol (FTP). The FTP functions are used to open, login and close connections, as well as upload, download, rename, delete, and get information on files from file servers.