Manual
H1>
(PHP 3, PHP 4 >= 4.0.0)
fopen--open file or URL
Describe
int fopen (string filename, string mode [, int use_include_path])
If filename starts with "http://" (case insensitive), this function opens the specified server with an HTTP 1.0 connection, which is requested using HTTP GET mode, and the file pointer points to the beginning of the returned server response file. A ' host: ' header with the base name of the requesting virtual host is sent.
Note that this file pointer allows you to re-retrieve the response of the body: You cannot use this function to access the HTTP response header.
The 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 this server does not support passive FTP mode, the error will be lost. You can go through FTP to open the file for either reading or writing (but not both).
If filename is "Php://stdin", "php://stdout", or "php://stderr" one of them, then the corresponding input and output stream will be opened. (This was introduced in PHP 3.0.13; In earlier versions, this file was called "/dev/stdin" or "/dev/fd/0" to access the input and output streams).
If filename is started in a different way, the file will be opened from the file system, returning a pointer to the open file.
Returns False if the open fails.
Mode can be any one of the following:
' R '-read-only open, pointer pointing to the beginning of the file;
' r+ '-open for Read and write, pointer to file start;
' W '-write-only open, pointer to file start, file size zeroed. If the file does not exist, it is new;
' w+ '-open for Read and write, pointer to file start, file size zeroed. If the file does not exist, it is new;
' A '-opens for append, pointing to end of file. If the file does not exist, try to create it;
' A + '-open for Read and write, pointer to end of file. If the file does not exist, try to create a new.
Note: Mode can contain the letter ' B '. This is only useful if the system distinguishes between binary and text files. (i.e. Windows. It is useless in Unix). If it is not needed, it will be ignored.
If you want to search for files 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:password@example.com/", "w");
If you is experiencing problems with reading and writing to files and you ' re using the Server module version of PHP, Reme Mber to make sure the files and directories you ' re using is accessible to the server process.
On the Windows platform, is 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 ().