Home >Backend Development >PHP Tutorial >PHP4 User Manual: Function-fopen_PHP Tutorial
fopen
(PHP 3, PHP 4 >= 4.0.0)fopen -- Open a file or URL description
int fopen (string filename, string mode [, int use_include_path])
If filename ends with "http: //"Start (case insensitive), then this function uses HTTP 1.0 connection to open the specified server. This page is requested using HTTP|GET mode, and the file pointer points to the beginning of the returned server response file. A Host: header is sent with the base name of the requested virtual host.
Note that this file pointer allows you to retrieve the body of the response: you cannot use this function to access HTTP response headers.
HTTP handle cannot be redirected below PHP 4.0.5. Because of this, directories must include trailing slashes.
If filename starts with "ftp://" (case-insensitive), a specified ftp connection to the server is opened, returning a pointer to the requested file. If this server does not support passive ftp mode, an error will be issued. You can open files for reading or writing via ftp (but not both at the same time).
If filename is one of "php://stdin", "php://stdout", or "php://stderr", the corresponding input and output stream will be opened. (This was introduced in PHP 3.0.13; in earlier versions, this file name was used like "/dev/stdin" or "/dev/fd/0" to access the input and output streams).
If filename starts otherwise, the file will be opened from the file system, returning a pointer to the open file.
If the opening fails, return FALSE.
mode can be any of the following:
r - open for reading only, the pointer points to the beginning of the file;
r+ - open for reading and writing, the pointer points to the beginning of the file;
w - open for writing only, the pointer points to the beginning of the file The file starts and the file size is reset to zero. If the file does not exist, create a new one;
w+ - Open for reading and writing, the pointer points to the beginning of the file, and the file size is cleared. If the file does not exist, create a new one;