Hướng dẫn file operation in php - thao tác với tệp trong php



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.

Nội dung chính ShowShow

  • Mở file - hàm PHP fopen()
  • Đóng file - hàm PHP fclose()
  • Đóng file - hàm PHP fclose()
  • Hàm PHP fclose() được sử dụng để đóng một file.
  • Hàm PHP fclose() được sử dụng để đóng một file.
  • Php thao tác các tập tin
  • 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 ?>
  • Việc xử lý tệp trong PHP là gì?
  • PHP có thể đọc từ tập tin không?
  • Có bao nhiêu chế độ xử lý tệp trong PHP?
  • PHP có thể ghi vào tệp không?


Nội dung chính

  • Mở file - hàm PHP fopen()
  • Đóng file - hàm PHP fclose()
  • Đọc file - hàm PHP fcfreadlose()
  • Ghi file - hàm PHP fwrite()
  • Xóa file - hàm PHP unlink()

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 tin
  • 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 ?>
  • Việc xử lý tệp trong PHP là gì?
  • PHP có thể đọc từ tập tin không?
  • Có bao nhiêu chế độ xử lý tệp trong PHP?
  • PHP có thể ghi vào tệp không?

Php thao tác các tập tin

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


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
CSS = Cascading Style Sheets
HTML = Hyper Text Markup Language
PHP = PHP Hypertext Preprocessor
SQL = Structured Query Language
SVG = Scalable Vector Graphics
XML = EXtensible Markup Language

Đọ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 PHP

Xử lý tệp trong PHP: Mở tệp

  • Xử lý tệp trong PHP: Đóng tệp
  • Đọc tập tin
  • Đọ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 ?>

Xử lý tệp trong PHP: Mở tệp

Xử lý tệp trong PHP: Đóng tệp

Example:

Đọ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

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 ?> Việc xử lý tệp trong PHP là gì?
PHP có thể đọc từ tập tin không? Có bao nhiêu chế độ xử lý tệp trong PHP?
r+ PHP có thể ghi vào tệp không?
Nội dung chính Mở file - hàm PHP fopen()
w+ Đóng file - hàm PHP fclose()
Đọc file - hàm PHP fcfreadlose() Ghi file - hàm PHP fwrite()
a+ Xóa file - hàm PHP unlink()
Hàm PHP fopen() được sử dụng để mở một file. Cú pháp:
x+ Mở tập tin

Xử lý tệp trong PHP: Đóng tệp

Đọc tập tin

NOTE:    

  • 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 ?>

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 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 ?>: The fread() function is used to read the contents of the data. The first parameter is the file pointer and the other is the file size in bytes.

Việc xử lý tệp trong PHP là gì?
<?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
    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
    function can be used to check if the “End-Of-File” (EOF) has been reached. This is very useful as we can loop through a file of unknown length. We can do this on every file in any mode.

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.
<?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
  • API thao tác tệp PHP, cực kỳ linh hoạt: nó cho phép bạn đọc các tệp vào một chuỗi hoặc thành một mảng, từ hệ thống tệp cục bộ hoặc một URL từ xa, theo các dòng, byte hoặc ký tự. The fgetc() function is used to read a character from a file.
fread (): hàm fread () được sử dụng để đọc nội dung của dữ liệu. Tham số đầu tiên là con trỏ tệp và cái còn lại là kích thước tệp tính bằng byte.: The fread() function is used to read the contents of the data. The first parameter is the file pointer and the other is the file size in bytes.: The fread() function is used to read the contents of the data. The first parameter is the file pointer and the other is the file size in bytes.
<?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");
    ?>
    
    4
    <?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");
    ?>
    
    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");
    ?>
    
    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
    To read the local disk files in PHP, file_get_contents() function is used. This function accepts the name and path of a disk file, and reads the entire file into a string variable at once.

Hàm Feof () có thể được sử dụng để kiểm tra xem có đạt được kết thúc của File (EOF) hay không. Điều này rất hữu ích vì chúng ta có thể lặp qua một tệp có độ dài không xác định. Chúng tôi có thể làm điều này trên mọi tệp trong bất kỳ chế độ nào. function can be used to check if the “End-Of-File” (EOF) has been reached. This is very useful as we can loop through a file of unknown length. We can do this on every file in any mode. function can be used to check if the “End-Of-File” (EOF) has been reached. This is very useful as we can loop through a file of unknown length. We can do this on every file in any mode.
<?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");
    ?>
    
    18
    <?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");
    ?>
    
    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");
    ?>
    
    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
    An alternative method of reading data from a file is PHP’s file() function. It accepts the name and path of the file and reads the entire file into an array, which has each element of the array representing one line of the file. We iterate through the array using foreach loop to access the elements of the array.

fgetc (): hàm fgetc () được sử dụng để đọc một ký tự từ một tệp. The fgetc() function is used to read a character from a file. The fgetc() function is used to read a character from a file.
<?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");
    ?>
    
    16
    <?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");
    ?>
    
    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");
    ?>
    
    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
    Both file_get_contents() and file() support reading data from URLs, using either the HTTP or FTP protocol. It reads an HTML file of the Web into an array.

<?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

  • fwrite (): hàm & nbsp; fwrite () & nbsp; hàm được sử dụng để ghi vào một tệp. Tham số đầu tiên của & nbsp; fwrite () & nbsp; chứa tên của tệp để ghi 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.

<?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
  • Ghi đè PHP: Demo demo.txt có chứa một số dữ liệu. Tất cả các dữ liệu hiện có sẽ bị xóa và chúng tôi bắt đầu với một tệp trống. “demo.txt” contains some data. All the existing data will be ERASED and we start with an empty file. “demo.txt” contains some data. All the existing data will be ERASED and we start with an empty file. “demo.txt” contains some data. All the existing data will be ERASED and we start with an empty file.

<?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
  • Ghi đè PHP: Demo demo.txt có chứa một số dữ liệu. Tất cả các dữ liệu hiện có sẽ bị xóa và chúng tôi bắt đầu với một tệp trống. The file_put_contents() function accepts a filename and the data to be written to the file. The file_put_contents() function accepts a filename and the data to be written to the file. The file_put_contents() function accepts a filename and the data to be written to the file.

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 ?>

  • Các hoạt động xử lý tệp và thư mục khác The filesize() function calculates the size of a file in bytes. It takes file name as an argument. The filesize() function calculates the size of a file in bytes. It takes file name as an argument. The filesize() function calculates the size of a file in bytes. It takes file name as an argument.

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
  • <?php
    fclose($handle);
    ?>
    
    2818
    <?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 The realpath() function is used to retrieve the absolute file path to a file. The realpath() function is used to retrieve the absolute file path to a file.18
    <?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 The realpath() function is used to retrieve the absolute file path to a file.
    The realpath() function is used to retrieve the absolute file path to a file.

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
  • <?php
    fclose($handle);
    ?>
    
    2818
    <?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");
    ?>
    
    7We can get detailed information about a particular file, including its ownership, permissions, and modification and access times, using stat() function. It returns this information as an associative array.We can get detailed information about a particular file, including its ownership, permissions, and modification and access times, using stat() function. It returns this information as an associative array.18
    <?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");
    ?>
    
    7We can get detailed information about a particular file, including its ownership, permissions, and modification and access times, using stat() function. It returns this information as an associative array.
    We can get detailed information about a particular file, including its ownership, permissions, and modification and access times, using stat() function. It returns this information as an associative array.

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
  • <?php
    fclose($handle);
    ?>
    
    2818
    <?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 We can check if a file is readable, writable or executable with the help of is_readable(), is_writable(), and is_executable() functions. We can check if a file is readable, writable or executable with the help of is_readable(), is_writable(), and is_executable() functions.18
    <?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 We can check if a file is readable, writable or executable with the help of is_readable(), is_writable(), and is_executable() functions.
    We can check if a file is readable, writable or executable with the help of is_readable(), is_writable(), and is_executable() functions.

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
  • Kiểm tra xem nó có phải là tệp hay không: hàm is_dir () trả về true nếu đối số được truyền cho nó là một thư mục. Hàm is_file () trả về true nếu đối số được truyền cho nó là một tệp.The is_dir() function returns true if the argument passed to it is a directory. The is_file() function returns true if the argument passed to it is a file.The is_dir() function returns true if the argument passed to it is a directory. The is_file() function returns true if the argument passed to it is a file.The is_dir() function returns true if the argument passed to it is a directory. The is_file() function returns true if the argument passed to it is a file.

<?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
  • Sao chép tệp: Hàm Copy () sao chép tệp từ vị trí này sang vị trí khác. Nó có nguồn tệp và đường dẫn đích như hai đối số The copy() function copies a file from one location to another location. It has the file source and destination path as two arguments The copy() function copies a file from one location to another location. It has the file source and destination path as two arguments The copy() function copies a file from one location to another location. It has the file source and destination path as two arguments

<?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
  • Đổi tên các tệp hoặc thư mục: hàm đổi tên () được sử dụng để đổi tên hoặc di chuyển một tệp (hoặc thư mục). Tôi lấy tên đường dẫn cũ và mới làm đối số. The rename() function is used to rename or movee a file (or directory). I takes the old and new path names as arguments. The rename() function is used to rename or movee a file (or directory). I takes the old and new path names as arguments. The rename() function is used to rename or movee a file (or directory). I takes the old and new path names as arguments.

<?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
  • Xóa các tệp hoặc thư mục: hàm hủy liên kết () được sử dụng để xóa một tệp. Nó lấy tên tệp làm đối số. The unlink() function is used to remove a file. It takes the filename name as an argument. The unlink() function is used to remove a file. It takes the filename name as an argument.

<?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
  • Khóa và mở khóa các tệp: Hàm Flock () khóa một tệp trước khi đọc hoặc ghi nó để không thể truy cập được bởi một quy trình khác. Thực hiện điều này làm giảm khả năng tham nhũng dữ liệu có thể xảy ra nếu hai quá trình cố gắng ghi dữ liệu khác nhau vào cùng một tệp ngay lập tức. Tham số đầu tiên lấy tên tệp. Tham số thứ hai cho Flock () Chỉ định loại khóa: Lock_ex tạo khóa độc quyền để viết, Lock_SH tạo khóa không độc quyền để đọc và Lock_un phá hủy khóa. The flock() function locks a file before reading or writing it so that it cannot be accessed by another process. Doing this reduces the possibility of data corruption that might occur if two processes attempt to write different data to the same file at the same instant. The first parameter takes the file name. The second parameter to flock() specifies the type of lock: LOCK_EX creates an exclusive lock for writing, LOCK_SH creates a non-exclusive lock for reading, and LOCK_UN destroys the lock. The flock() function locks a file before reading or writing it so that it cannot be accessed by another process. Doing this reduces the possibility of data corruption that might occur if two processes attempt to write different data to the same file at the same instant. The first parameter takes the file name. The second parameter to flock() specifies the type of lock: LOCK_EX creates an exclusive lock for writing, LOCK_SH creates a non-exclusive lock for reading, and LOCK_UN destroys the lock.

<?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.