Phần này hướng dẫn bạn xử lý file trong PHP, PHP cho phép chúng ta tạo file, đọc từng dòng của file, đọc file theo ký tự, ghi file, nối thêm nội dung vào file, xóa file và đóng file. Show
Nội dung chính ShowShow
Nội dung chính
Mở file - hàm PHP fopen()Hàm PHP fopen() được sử dụng để mở một file. Cú pháp: fopen (string $filename , string $mode [, bool $use_include_path = false [, resource $context ]]) Ví dụ: <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?> Đóng file - hàm PHP fclose()Hàm PHP fclose() được sử dụng để đóng một file. Cú pháp: Ví dụ: <?php fclose($handle); ?> Đóng file - hàm PHP fclose()Hàm PHP fclose() được sử dụng để đóng một file. Cú pháp: string fread(resource $handle, int $length ) Ví dụ: <?php $filename = "D:\\myfile.txt"; $handle = fopen($filename, "r");//mở file ở chế độ đọc $contents = fread($handle, filesize($filename));//đọc file echo $contents;//in nội dung file ra màn hình fclose($handle);//đóng file ?> Đóng file - hàm PHP fclose() Hàm PHP fclose() được sử dụng để đóng một file.Php thao tác các tập tin Cú pháp: int fwrite(resource $handle , string $string [, int $length ]) Ví dụ: <?php $fp = fopen('data.txt', 'w');//mở file ở chế độ ghi fwrite($fp, 'hello '); fwrite($fp, 'php file'); fclose($fp); echo "File được ghi thành công."; ?> Đóng file - hàm PHP fclose() File được ghi thành công. Hàm PHP fclose() được sử dụng để đóng một file.Php thao tác các tập tin Cú pháp: bool unlink ( string $filename [, resource $context ]) Ví dụ: <?php unlink('data.txt'); echo "File được xóa thành công."; ?> Đóng file - hàm PHP fclose() <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>0 Đọc file - hàm PHP fcfreadlose() Xử lý tập tin là một phần quan trọng của bất kỳ ứng dụng web nào. Bạn thường cần mở và xử lý một tệp cho các tác vụ khác nhau.Show
Php thao tác các tập tinHàm readfile () Bài tập PHP Xử lý tệp trong PHP: Mở tệp Xử lý tệp trong PHP: Đóng tệp Hàm readfile ()Bài tập PHP Xử lý tệp trong PHP: Mở tệp Xử lý tệp trong PHP: Đóng tệp Đọc tập tin Viết tập tin readfile()8 $file= fopen("demo.txt", "r"); 0 $file= fopen("demo.txt", "r"); 1 $file= fopen("demo.txt", "r"); 2 $file= fopen("demo.txt", "r"); 3 ?> Bài tập PHPXử lý tệp trong PHP: Mở tệp
Xử lý tệp trong PHP: Mở tệpXử lý tệp trong PHP: Đóng tệpExample: Đọc tập tin <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>5 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>6 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>6 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 Viết tập tin
Xử lý tệp trong PHP: Đóng tệpĐọc tập tin NOTE:
Example: Việc xử lý tệp trong PHP là gì? <?php fclose($handle); ?>2 <?php fclose($handle); ?>3 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>3 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 PHP có một số chức năng để tạo, đọc, tải lên và chỉnh sửa các tệp. Đọc tập tinViết tập tin
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>15 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>16 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>19 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>12 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>17 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>45 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>46 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>47 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>50 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>51 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>52 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>54 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>58 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>59 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>52 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>54 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>58 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>59 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>52 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>54 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>58 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>59 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>52 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>54 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>58 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>59 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>52 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>54 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 Lưu ý: Trong trường hợp các liên kết mạng chậm, việc đọc một tệp từ xa trong các đoạn, đó là hiệu quả hơn, để tối đa hóa hiệu quả của băng thông mạng có sẵn. Hàm fgets () có thể đọc một số byte cụ thể từ một tệp.In case of slow network links, it is more efficient to read a remote file in “chunks,” to maximize the efficiency of available network bandwidth. fgets() function can read a specific number of bytes from a file.In case of slow network links, it is more efficient to read a remote file in “chunks,” to maximize the efficiency of available network bandwidth. fgets() function can read a specific number of bytes from a file.In case of slow network links, it is more efficient to read a remote file in “chunks,” to maximize the efficiency of available network bandwidth. fgets() function can read a specific number of bytes from a file. <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>66 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>67 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>68 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>71 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>72 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>73 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>47 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>76 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>66 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>67 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>68 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>71 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>72 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>73 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>47 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>66 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>67 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>68 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>71 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>72 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>73 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>47 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>66 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>67 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>68 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>10 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>11 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>71 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>72 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>73 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>47 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 Viết tập tin
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>78 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>79 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>40 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
file_put_contents (): hàm file_put_contents () chấp nhận tên tệp và dữ liệu sẽ được ghi vào tệp. <?php fclose($handle); ?>20 <?php fclose($handle); ?>21 <?php fclose($handle); ?>22 <?php fclose($handle); ?>23 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>20 <?php fclose($handle); ?>21 <?php fclose($handle); ?>22 <?php fclose($handle); ?>23 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>20 <?php fclose($handle); ?>21 <?php fclose($handle); ?>22 <?php fclose($handle); ?>23 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 readfile()8 $file= fopen("demo.txt", "r"); 0 $file= fopen("demo.txt", "r"); 1 $file= fopen("demo.txt", "r"); 2 $file= fopen("demo.txt", "r"); 3 ?>
Tính toán kích thước tệp: Hàm fileSize () Tính toán kích thước của tệp tính bằng byte. Nó lấy tên tệp làm đối số. <?php fclose($handle); ?>26 <?php fclose($handle); ?>27 <?php fclose($handle); ?>28 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>26 <?php fclose($handle); ?>27 <?php fclose($handle); ?>28 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>26 <?php fclose($handle); ?>27 <?php fclose($handle); ?>28 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
Tìm đường dẫn tệp tuyệt đối: hàm realpath () được sử dụng để truy xuất đường dẫn tệp tuyệt đối đến một tệp. <?php fclose($handle); ?>34 <?php fclose($handle); ?>27 <?php fclose($handle); ?>36 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>34 <?php fclose($handle); ?>27 <?php fclose($handle); ?>36 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>34 <?php fclose($handle); ?>27 <?php fclose($handle); ?>36 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php fclose($handle); ?>2818 <?php fclose($handle); ?>34 <?php fclose($handle); ?>27 <?php fclose($handle); ?>36 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 We can also use the pathinfo() function. It returns an array containing the file’s path, name, and extension. We can also use the pathinfo() function. It returns an array containing the file’s path, name, and extension.18 <?php fclose($handle); ?>34 <?php fclose($handle); ?>27 <?php fclose($handle); ?>36 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 We can also use the pathinfo() function. It returns an array containing the file’s path, name, and extension. We can also use the pathinfo() function. It returns an array containing the file’s path, name, and extension. Lưu ý: Chúng tôi cũng có thể sử dụng hàm pathinfo (). Nó trả về một mảng chứa đường dẫn, tên và phần mở rộng của tệp. <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>102 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>104 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>102 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>104 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>102 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>104 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
Truy xuất các thuộc tính tệp: Chúng tôi có thể nhận được thông tin chi tiết về một tệp cụ thể, bao gồm quyền sở hữu, quyền và thời gian sửa đổi và truy cập của nó, sử dụng hàm stat (). Nó trả về thông tin này như một mảng kết hợp. <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>110 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>112 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>110 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>112 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>110 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>112 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
Kiểm tra các chế độ: Chúng tôi có thể kiểm tra xem một tệp có thể đọc được, có thể ghi hoặc thực thi với sự trợ giúp của các hàm is_readable (), is_writable () và is_executable (). <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>110 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>119 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>121 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>122 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>123 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>124 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>126 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>127 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>128 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>130 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>131 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>132 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>110 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>119 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>121 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>122 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>123 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>124 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>126 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>127 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>128 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>130 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>131 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>132 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>110 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>119 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>121 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>122 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>123 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>124 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>126 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>127 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>128 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>130 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>131 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>132 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php fclose($handle); ?>30 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>139 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>141 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>142 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>144 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>139 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>141 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>142 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>144 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>139 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>141 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>142 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>144 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>139 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>141 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>142 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>144 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>149 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>151 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>152 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>154 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>149 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>151 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>152 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>154 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>149 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>151 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>152 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>154 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>149 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>151 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>152 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>154 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>161 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>163 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>164 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>166 ____23 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>161 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>163 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>164 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>166 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>171 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>172 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>173 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>174 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>176 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>179 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>161 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>163 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>164 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>166 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>171 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>172 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>173 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>174 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>176 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>179 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>161 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>163 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>164 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>166 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>171 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>172 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>173 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>174 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>176 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>179 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>18 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>183 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>185 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>186 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>188 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>183 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>185 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>186 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>188 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>183 <?php fclose($handle); ?>27 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>185 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>186 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>188 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php fclose($handle); ?>29 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>145 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>13 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7
<?php $filename = "D:\\myfile.txt"; $handle = fopen($filename, "r");//mở file ở chế độ đọc $contents = fread($handle, filesize($filename));//đọc file echo $contents;//in nội dung file ra màn hình fclose($handle);//đóng file ?>9018 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>195 <?php fclose($handle); ?>20 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>197 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>198 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>199 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>100 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>101 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>102 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php fclose($handle); ?>23 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>195 <?php fclose($handle); ?>20 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>197 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>198 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>199 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>100 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>101 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>102 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php fclose($handle); ?>23 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>195 <?php fclose($handle); ?>20 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>197 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>198 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>199 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>100 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>101 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>102 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>14 <?php fclose($handle); ?>23 <?php $handle = fopen("D:\\folder\\file.txt", "r"); ?>7 Đọc và viết tệp là các nhiệm vụ cơ bản mà bất kỳ nhà phát triển PHP nào cũng nên biết cách hoàn thành; Bài viết này bao gồm cả hai nhiệm vụ này, và nhiều hơn nữa. Nó bắt đầu với một minh chứng về cách đọc các tệp cục bộ và từ xa, cũng như cách tạo các tệp mới hoặc nối dữ liệu vào các tệp hiện có. Sau đó, nó chuyển sang thao tác thư mục theo PHP và giải thích nhiều chức năng thư mục và tệp PHP. Với điều này, chúng tôi đã kết thúc việc xử lý tập tin này trong bài viết của PHP. Tôi hy vọng xử lý tập tin không nên là một vấn đề. Kiểm tra & nbsp; đào tạo chứng nhận PHP & nbsp; bởi Edureka, & nbsp;heck out the PHP Certification Training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.heck out the PHP Certification Training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. Có một câu hỏi cho chúng tôi? Vui lòng đề cập đến nó trong phần bình luận của xử lý tập tin trong Php và tôi sẽ liên hệ lại với bạn. Việc xử lý tệp trong PHP là gì?Xử lý tệp trong PHP: Mở tệp hàm fopen () được sử dụng để mở tệp.Tham số đầu tiên chứa tên của tệp sẽ được mở và tham số thứ hai cho biết tệp sẽ được mở trong chế độ nào.Hàm fopen () tạo ra một con trỏ trỏ đến tệp được đề cập.The fopen() function is used to open a file. The first parameter contains the name of the file to be opened and the second parameter tells in which mode the file should be opened. fopen() function creates a pointer which points to the file mentioned.The fopen() function is used to open a file. The first parameter contains the name of the file to be opened and the second parameter tells in which mode the file should be opened. fopen() function creates a pointer which points to the file mentioned. PHP có thể đọc từ tập tin không?Php Read File - fread () hàm fread () đọc từ một tệp mở.Tham số đầu tiên của fread () chứa tên của tệp để đọc và tham số thứ hai chỉ định số lượng byte tối đa để đọc.The fread() function reads from an open file. The first parameter of fread() contains the name of the file to read from and the second parameter specifies the maximum number of bytes to read.The fread() function reads from an open file. The first parameter of fread() contains the name of the file to read from and the second parameter specifies the maximum number of bytes to read. Có bao nhiêu chế độ xử lý tệp trong PHP?Trong xử lý tệp PHP, có bốn bộ chế độ có thể.Đó là, {r và r+} - để đọc các tệp hiện có.four sets of possible modes. These are, {r and r+} – To read the existing files.four sets of possible modes. These are, {r and r+} – To read the existing files.four sets of possible modes. These are, {r and r+} – To read the existing files. PHP có thể ghi vào tệp không?PHP ghi vào tệp - fwrite () hàm fwrite () được sử dụng để ghi vào tệp.Tham số đầu tiên của fwrite () chứa tên của tệp để ghi vào và tham số thứ hai là chuỗi được viết.The fwrite() function is used to write to a file. The first parameter of fwrite() contains the name of the file to write to and the second parameter is the string to be written.The fwrite() function is used to write to a file. The first parameter of fwrite() contains the name of the file to write to and the second parameter is the string to be written.The fwrite() function is used to write to a file. The first parameter of fwrite() contains the name of the file to write to and the second parameter is the string to be written. |