مدیریت فایل‌ها در PHP

عمل بر روی فایل PHP

PHP دارای چندین تابع برای ایجاد، خواندن، آپلود و ویرایش فایل است.

توجه داشته باشید:لطفاً در عمل بر روی فایل احتیاط کنید!

در هنگام عمل بر روی فایل باید بسیار دقت کنید. اگر اشتباه کنید، ممکن است بسیار خراب شود. اشتباهات رایج عبارتند از:

  • Edit Errors in Files
  • Hard Drive Filled with Garbage Data
  • Accidentally Deleted File Content

PHP readfile() Function

The readfile() function reads the file and writes it to the output buffer.

Assuming we have a text file named "webdictionary.txt" stored on the server, like this:

AJAX = Asynchronous JavaScript and XML
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

The PHP code to read this file and write to the output stream is as follows (if read successfully, the readfile() function returns the number of bytes):

Example

<?php
echo readfile("webdictionary.txt");
?>

Run Instance

If all you want to do is open a file and read its content, then the readfile() function is very useful.

The next section will explain more about file handling.

PHP Filesystem Reference Manual

For a complete PHP Filesystem Reference Manual, please visit the one provided by CodeW3C.com PHP Filesystem Reference Manual.