Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luậnfopen[] – PHP fopen[] function is used to open a file. First parameter of fopen[] contains name of the file which is to be opened and second parameter tells about mode in which file needs to be opened, e.g.,
Xử lý tập tin là cần thiết cho bất kỳ ứng dụng. Đối với một số nhiệm vụ được thực hiện tập tin cần được xử lý. Xử lý tệp trong PHP tương tự vì xử lý tệp được thực hiện bằng cách sử dụng bất kỳ ngôn ngữ lập trình nào như C. PHP có nhiều chức năng để làm việc với các tệp bình thường. Những chức năng đó là:
- 1] Hàm fopen [] - php fopen [] được sử dụng để mở tệp. Tham số đầu tiên của fopen [] chứa tên của tệp sẽ được mở và tham số thứ hai cho biết về chế độ trong đó tệp cần được mở, ví dụ: Opens a file for write only. If file not exist then new file is created and if file already exists then contents of file is erased.
- Các tệp có thể được mở trong bất kỳ chế độ nào sau đây: File is opened for read only.
- Mùi W Wi - Mở một tệp chỉ để ghi. Nếu tệp không tồn tại thì tệp mới được tạo và nếu tệp đã tồn tại thì nội dung của tệp sẽ bị xóa. File is opened for write only. File pointer points to end of file. Existing data in file is preserved.
- Tệp - tập tin chỉ được mở để đọc. Opens file for read and write. If file not exist then new file is created and if file already exists then contents of file is erased.
- Một tập tin - một tập tin chỉ được mở để viết. Tệp con trỏ trỏ đến cuối tệp. Dữ liệu hiện có trong tập tin được bảo tồn. File is opened for read/write.
- Mùi W+ - Mở tệp để đọc và viết. Nếu tệp không tồn tại thì tệp mới được tạo và nếu tệp đã tồn tại thì nội dung của tệp sẽ bị xóa. File is opened for write/read. File pointer points to end of file. Existing data in file is preserved. If file is not there then new file is created.
- Tệp R+ - Tệp được mở để đọc/ghi. New file is created for write only.
Tệp A+ - Tệp được mở để viết/đọc. Tệp con trỏ trỏ đến cuối tệp. Dữ liệu hiện có trong tập tin được bảo tồn. Nếu tệp không có thì tệp mới được tạo.fread[] –– After file is opened using fopen[] the contents of data are read using fread[]. It takes two arguments. One is file pointer and another is file size in bytes, e.g.,
2] fread [], sau khi tệp được mở bằng fopen [] Nội dung của dữ liệu được đọc bằng fread []. Nó có hai đối số. Một là con trỏ tệp và một là kích thước tệp tính bằng byte, ví dụ:fwrite[] – New file can be created or text can be appended to an existing file using fwrite[] function. Arguments for fwrite[] function are file pointer and text that is to written to file. It can contain optional third argument where length of text to written is specified, e.g.,
3] fwrite [] - Tệp mới có thể được tạo hoặc văn bản có thể được nối vào một tệp hiện có bằng hàm fwrite []. Đối số cho hàm fwrite [] là con trỏ tệp và văn bản được ghi vào tệp. Nó có thể chứa đối số thứ ba tùy chọn trong đó độ dài của văn bản để viết được chỉ định, ví dụ:
Wikipedia
4] fclose [] - Tệp được đóng bằng hàm fclose []. Đối số của nó là tệp cần được đóng, ví dụ:Swasthik. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Tài liệu tham khảo trên WWWikipedia
Tiếp theo → ← Prev
Hàm php fopen [] được sử dụng để mở tệp hoặc url và trả về tài nguyên. Hàm fopen [] chấp nhận hai đối số: $ fileName và $ Mode. Tên tệp $ đại diện cho tệp được mở và $ Mode đại diện cho chế độ tệp, ví dụ chỉ là đọc, đọc-viết, chỉ ghi, v.v.
Cú pháp
Php Mở Chế độ
r | Mở tệp ở chế độ chỉ đọc. Nó đặt con trỏ tệp ở đầu tệp.read-only mode. It places the file pointer at the beginning of the file. |
R+ | Mở tệp ở chế độ đọc-viết. Nó đặt con trỏ tệp ở đầu tệp.read-write mode. It places the file pointer at the beginning of the file. |
w | Mở tệp ở chế độ chỉ ghi. Nó đặt con trỏ tệp đến đầu tệp và cắt tệp về độ dài bằng không. Nếu không tìm thấy tệp, nó sẽ tạo một tệp mới.write-only mode. It places the file pointer to the beginning of the file and truncates the file to zero length. If file is not found, it creates a new file. |
W+ | Mở tệp ở chế độ đọc-viết. Nó đặt con trỏ tệp đến đầu tệp và cắt tệp về độ dài bằng không. Nếu không tìm thấy tệp, nó sẽ tạo một tệp mới.read-write mode. It places the file pointer to the beginning of the file and truncates the file to zero length. If file is not found, it creates a new file. |
một | Mở tệp ở chế độ chỉ ghi. Nó đặt con trỏ tệp đến cuối tệp. Nếu không tìm thấy tệp, nó sẽ tạo một tệp mới.write-only mode. It places the file pointer to the end of the file. If file is not found, it creates a new file. |
A+ | Mở tệp ở chế độ đọc-viết. Nó đặt con trỏ tệp đến cuối tệp. Nếu không tìm thấy tệp, nó sẽ tạo một tệp mới.read-write mode. It places the file pointer to the end of the file. If file is not found, it creates a new file. |
x | Tạo và mở tệp ở chế độ chỉ ghi. Nó đặt con trỏ tệp ở đầu tệp. Nếu tệp được tìm thấy, hàm fopen [] trả về sai.write-only mode. It places the file pointer at the beginning of the file. If file is found, fopen[] function returns FALSE. |
x+ | Nó giống như X nhưng nó tạo và mở tệp ở chế độ đọc-viết.read-write mode. |
c | Mở tệp ở chế độ chỉ ghi. Nếu tệp không tồn tại, nó được tạo ra. Nếu nó tồn tại, nó không bị cắt ngắn [trái ngược với 'W'], cũng như cuộc gọi cho chức năng này không thành công [như trường hợp với 'X']. Con trỏ tệp được định vị ở đầu tệpwrite-only mode. If the file does not exist, it is created. If it exists, it is neither truncated [as opposed to 'w'], nor the call to this function fails [as is the case with 'x']. The file pointer is positioned on the beginning of the file |
C+ | Nó giống như C nhưng nó mở tệp ở chế độ đọc-viết.read-write mode. |
Ví dụ về tệp mở php
TÍNH TOÁN TÍNH NĂNG TIẾP THEOPHP Read File
← Tiếp theo →
Nhận xét
- Gửi phản hồi của bạn đến [Email & NBSP; được bảo vệ]