(PHP 3, PHP 4> = 4.0.0)
Fopen -- open a file or URL
Int fopen (string filename, string mode [, int use_include_path])
If filename starts with "http: //" (case insensitive), this function uses HTTP 1.0 to connect to open the specified server. this page is requested in http get mode, the file pointer points to the start point of the response file of the returned server. A 'host: 'header with the basic name of the requesting VM is sent.
Note: This file pointer allows you to retrieve the body of the response again: you cannot use this function to access the HTTP response header.
HTTP handle cannot be redirected under PHP 4.0.5. Because of this, directories must include trailing slashes.
If filename starts with "ftp: //" (case insensitive), a specified ftp Connection Server is opened and a pointer to the requested file is returned. If the server does not support the Passive ftp mode, an error is returned. You can open a file for reading or writing through ftp (but not both ).
If filename is "php: // stdin", "php: // stdout", or "php: // stderr, the corresponding input and output streams are opened. (This was introduced in PHP 3.0.13; in earlier versions, this file name is used like "/dev/stdin" or "/dev/fd/0" to access the input/output stream ).
If filename starts in another way, the file will be opened from the file system and a pointer to open the file will be returned.
If it fails to be opened, FALSE is returned.
Mode can be any of the following:
'R'-read-only open, pointer pointing to file start;
'R + '-indicates that the read/write operation is enabled, and the pointer points to the start of the file;
'W'-Write-only open, pointer pointing to the beginning of the file, the file size is cleared. If the file does not exist, it is created;
'W + '-for read/write operations, the pointer points to the start of the file, and the file size is cleared. If the file does not exist, it is created;
'A'-for append opening, the pointer points to the end of the file. If the file does not exist, try to create a new one;
'A + '-open for read/write and point the pointer to the end of the file. If the file does not exist, try to create a new one.
Note: the mode can contain the 'B' letter '. This is useful only when binary and text files are distinguished by the system. (I. e. Windows. it is useless in Unix ). If not, it is ignored.
If you want to search for a file in include_path, you can use the optional third parameter and set it to "1 ".
Example 1. fopen () example
$ Fp = fopen ("/home/rasmus/file.txt", "r ");
$ Fp = fopen ("/home/rasmus/file.gif", "wb ");
$ Fp = fopen ("http://www.php.net/", "r ");
$ Fp = fopen ("ftp: // user: email@example.com/", "w ");
If you are experiencing problems with reading and writing to files and you're using the server module version of PHP, remember to make sure that the files and directories you're using are accessible to the server process.
On the Windows platform, be careful to escape any backslashes used in the path to the file, or use forward slashes.
$ Fp = fopen ("c: \ data \ info.txt", "r ");
See fclose (), fsockopen (), socket_set_timeout (), and popen ().