1.resource fopen (String $filename, String $mode [, bool $use _include_path [, Resource $zcontext]])
function Function:
fopen () binds the name resource specified by filename to a stream. If filename is "scheme://..." Format, the Search protocol processor (also known as the Encapsulation Protocol) is treated as a url,php to handle this pattern. If the protocol has not yet been registered for encapsulation, PHP will issue a message to help examine potential problems in the script and continue with filename as a normal file name.
If PHP thinks that filename specifies a local file, it will attempt to open a stream on that file. The file must be accessible by PHP, so you need to confirm that the file access permission allows that access. If Safe mode is activated or open_basedir is applied, further restrictions apply.
If PHP believes that filename specifies a signed protocol, and that the protocol is registered as a network url,php will check and confirm that Allow_url_fopen has been activated. If it is off, PHP will issue a warning, and fopen's call fails.
FileName:Specifies the file or URL to open.
mode:Specifies the type of access required to the file/stream.
include_path:Optionally, you can set this parameter to 1 or true if you also need to retrieve the file in Include_path.
Context:Optionally, specify the context of the file handle, and the context is a set of options that can fix the behavior of the stream.
possible values for the mode parameter
Mode description
The "R" read-only mode opens, pointing the file pointer to the file header.
The "r+" read-write mode opens, pointing the file pointer to the file header.
The "W" Write method opens, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try to create it.
The "w+" read-write mode opens, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try to create it.
The "A" write opens, pointing the file pointer to the end of the file. If the file does not exist, try to create it.
A + read-write mode opens, pointing the file pointer to the end of the file. If the file does not exist, try to create it.
"X"
Creates and opens in writing, pointing the file pointer to the file header. If the file already exists, the fopen () call fails and returns false, and generates an E_warning level error message. If the file does not exist, try to create it.
This specifies o_excl| for the underlying open (2) system call The o_creat tag is equivalent.
This option is supported by PHP 4.3.2 and later versions and can only be used on local files.
"X+"
Creates and opens read-write, pointing the file pointer to the file header. If the file already exists, the fopen () call fails and returns false, and generates an E_warning level error message. If the file does not exist, try to create it.
This specifies o_excl| for the underlying open (2) system call The o_creat tag is equivalent.
This option is supported by PHP 4.3.2 and later versions and can only be used on local files.
Note:
Different operating system families have different end-of-line habits. When you write a text file and want to insert a new row, you need to use the line ending symbol that matches the operating system. Unix-based systems use \ n as the line-ending character, and the Windows-based system uses \ r \ n as the line-ending character, and the Macintosh-based system uses \ r as the line-ending character.
If you write to a file with an incorrect line-ending symbol, other applications may behave strangely when they open the file.
A text conversion token (' t ') is provided under Windows to transparently convert \ n to \ r \ n. With this counterpart, you can also use ' B ' to force binary mode so that the data is not converted. To use these tags, either use ' B ' or ' t ' as the last character of the mode parameter.
The default conversion mode relies on SAPI and the PHP version used, so it is always necessary to specify the appropriate markup for ease of porting. If you are manipulating plain text files and using \ n as the line terminator in the script, but also expect that these files can be read by other applications such as Notepad, use ' t ' in mode. Use ' B ' in all other cases.
If you do not specify a ' B ' tag when working with binaries, you may encounter some strange problems, including broken picture files and strange questions about \ r \ n characters.
http://www.bkjia.com/PHPjc/328060.html www.bkjia.com true http://www.bkjia.com/PHPjc/328060.html techarticle 1.resource fopen (String $filename, String $mode [, bool $use _include_path [, Resource $zcontext]]) function function: fopen () will file Name specifies a resource that is bound to a stream. Like ...