PHP FILE OPERATIONS
To open / access the files in PHP you can use fopen (). The function fopen () can access files from the file system, or via HTTP or FTP on the Internet.
The syntax is:
To open / access the files in PHP you can use fopen (). The function fopen () can access files from the file system, or via HTTP or FTP on the Internet.
The syntax is:
fopen (filename, access mode);
Filename is the file to be opened, while the access mode is a method of accessing the file if the file is accessible only to be read, written or added. Mode of access.
Here's Access Mode and the function of each access mode:
a
Opening files to be changed. The data will be added at the end of the file that is accessible, if the file is not found, then PHP will automatically create the file.
a+
Opening a file to be changed and read. The data will be added at the end of the file that is accessible, if the file is not found, then PHP will automatically create the file
r
Opening files for read only
r+
Opening files for reading and writing. The data will be written in the beginning of the file
w
Opening file for writing only. Data in the old file will be lost and replaced with new data entered. If the file is not found, PHP will automatically create the file
w+
Opening a file to be written and read. Data in the old file will be lost and replaced with new data entered. If the file is not found, PHP will automatically create the file
To view the contents of the files is used fgets($filename,length), $ filename is a variable file to be opened while the length shows the number of characters that were taken. At the function fgets () is any HTML tags will be executed, so that HTML tags can not be executed, then there is fgetss ()functions.
As for the input data into the file, use the function fputs($filename,$variabel_data), the contents of data to be included in the $variabel_data while $filename is the destination file.
Function feof (). The usefulness of this function is to determine the end of a file, if it is at the end of the file this function will be worth True.
Here's Access Mode and the function of each access mode:
a
Opening files to be changed. The data will be added at the end of the file that is accessible, if the file is not found, then PHP will automatically create the file.
a+
Opening a file to be changed and read. The data will be added at the end of the file that is accessible, if the file is not found, then PHP will automatically create the file
r
Opening files for read only
r+
Opening files for reading and writing. The data will be written in the beginning of the file
w
Opening file for writing only. Data in the old file will be lost and replaced with new data entered. If the file is not found, PHP will automatically create the file
w+
Opening a file to be written and read. Data in the old file will be lost and replaced with new data entered. If the file is not found, PHP will automatically create the file
To view the contents of the files is used fgets($filename,length), $ filename is a variable file to be opened while the length shows the number of characters that were taken. At the function fgets () is any HTML tags will be executed, so that HTML tags can not be executed, then there is fgetss ()functions.
As for the input data into the file, use the function fputs($filename,$variabel_data), the contents of data to be included in the $variabel_data while $filename is the destination file.
Function feof (). The usefulness of this function is to determine the end of a file, if it is at the end of the file this function will be worth True.
0 comments:
Post a Comment