PHP Tutorial fopen function Usage (open create file)
In a lot of time we need to create a file, especially to generate static page time, we often use in PHP fopen this function to create a new file, its original is how the file exists on the append, does not exist can be created, there are a lot of parameters, with you according to your needs to define parameters.
$xxx = fopen ("Text.txt", ' W ', ture)
*/
$fopen = ' fopen.txt ';
$str = ' Write a file www.bkjia.com ';
if (file_exists ($fopen))
{
$h = fopen ($fopen, ' A + ');
if (fwrite ($h, $STR))
{
Echo ' content adds success ';
}
Fclose ();
}
Else
{
$h = fopen ($fopen, ' w+ ');
if (fwrite ($h, $STR))
{
Echo ' file written successfully ';
}
Fclose ();
}
$file = fopen ("Test.txt", "R");
$file = fopen ("/home/mb.php100.com/test.txt", "R");
$file = fopen ("/home/test/test.gif", "WB");
$file = fopen ("http://www.bkjia.com/", "R");
$file = fopen ("Ftp://user:password@example.com/test.txt", "w");
/*
Detailed description of the fopen function
Definition and usage
The fopen () function opens the file or URL.
If open fails, this function returns FALSE.
Grammar
fopen (filename,mode,include_path,context) parameter description
FileName is required. Specifies the file or URL to open.
Mode required. Specifies the type of access required to the file/stream. The possible values are shown in the following table.
Include_path is optional. If you also need to retrieve the file in Include_path, you can set the parameter to 1 or true.
The context is optional. Rules
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. Create.
The "w+" read-write mode opens, pointing the file pointer to the file header and truncating the file size to zero. Create.
The "A" write opens, pointing the file pointer to the end of the file. The file does not exist for creation.
A + read-write mode opens, pointing the file pointer to the end of the file. The file does not exist for creation.
*/
?>
http://www.bkjia.com/PHPjc/445397.html www.bkjia.com true http://www.bkjia.com/PHPjc/445397.html techarticle PHP Tutorial fopen function Usage (open create file) in a lot of time we need to create files, especially when generating static pages, we often use in PHP fopen this function to ...