PHP fopen function
The PHP fopen function can be used to open a file or URL content, such as any "openable through fopen" file under the root directory of the webpage or a file of an external resource, which can be applied to the opened file through different open modes (fopen mode) Above, PHP designers can easily modify the file or use the content of the file, but the use of PHP fopen often encounters the problem of server permission settings, and often encounters the conditional restrictions of different operating systems. You need to be familiar with the work of executing PHP fopen when using it. The environment is less error-prone.
PHP fopen function syntax rules
When PHP fopen successfully opens a file or URL, it will automatically return the pointer resource, if it fails, it will return FALSE.
$filename -Specifies the file or URL to be opened. It must be the permission and content that PHP can open.
PHP fopen function common mode table ($mode)
mode | Description |
'r' | Open in reading mode, the pointer points to the beginning of the file. |
'r+' | Open in read-write mode, the pointer points to the beginning of the file. |
'w' | Open in writing mode, the pointer points to the beginning of the file and the file size is truncated to zero. Try to create the file if it does not exist. |
'w+' | Open in read-write mode, the pointer points to the beginning of the file and the file size is truncated to zero. Try to create the file if it does not exist. |
'a' | Open in writing mode, the pointer points to the end of the file, if the file does not exist, try to create it. |
'a+' | Open in read-write mode, the pointer points to the end of the file, if the file does not exist, try to create it. |
'x' | Create and open in write mode, if the file already exists, fopen returns false and generates an E_WARNING level error message |
'x+' | Create and open in read-write mode. If the file already exists, fopen returns false and generates an E_WARNING level error message |
'c' | Open the file in write mode, the pointer points to the beginning of the file, if the file does not exist, fopen tries to create it. |
'c+' | Open the file in read-write mode, the pointer points to the beginning of the file, if the file does not exist, fopen tries to create it. |
$context -PHP 5.0.0 new features, support for context.
PHP fopen function example
$handle = fopen("/home/fopenbox/test.txt", "r");
$handle = fopen("/home/fopenbox/test.gif", "wb");
$handle = fopen( "http://www.php.net", "r");
$handle = fopen("ftp://user:password@example.com/test.txt", "w");
?>
Post a Comment
0 Comments