Opening and closing files

All functions use the file as a parameter called charge. „Pointer to the file.” It is a variable that specifies the file open. This is necessary because the script can open multiple files at once and at all work simultaneously.lux-standart.ru


This index file is returned by fopen (filename, string mode). The second parameter specifies the mode to open the file. Mode must be chosen according to what you want to do with the file. Possible modes are:
, r ‚
read-only file; The internal file pointer is placed at the beginning of the file
r + ‚
file for reading and writing; The internal file pointer is placed at the beginning of the file
,w’
the file for writing only; The internal file pointer is placed at the end of the file; the contents of the file is destroyed (the length of the file is changed to zero); If the file does not exist PHP tries to create
w + ‚
file to read and write; The internal file pointer is placed at the end of the file; the contents of the file is destroyed (the length of the file is changed to zero); If the file does not exist
,a’
the file for writing only; The internal file pointer is placed at the end of the file; If the file does not exist PHP tries to create
The „internal file pointer” determines at which point would start to write to the file, if it began to write or read from the file after the file is opened. If at the end – that is that the data is appended at the end.

Example
<?

$ fp = fopen („file.txt”, „r”);

?>

The variable $ fp now contains a pointer to a file file.txt. This indicator must enter each function that somehow operates on this file.
If you opened the file, you now need to somehow close. If you do not close the file manually, PHP will do it for us at the end of the script. It makes no difference if you are operating on only one file or eg. When data is saved to the file were no longer interested. Otherwise the matter if the data is saved to a file you want to read it later – after closing the file changes it will be visible. And to close a file, use the function fclose (int index).

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close