Home  >  Article  >  Backend Development  >  PHP4 User Manual: Function-fopen_PHP Tutorial

PHP4 User Manual: Function-fopen_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:22:20898browse

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;


a - open for appending, with the pointer pointing to the end of the file. If the file does not exist, try to create a new one;
a+ - Open for reading and writing, the pointer points to the end of the file. If the file does not exist, try creating a new one.
Note: mode can contain the letter b. This is only useful if the system differentiates between binary and text files. (i.e. Windows. It's useless in Unix). If not required, it will be ignored.
If you want to search for files in the website construction server script class PHPPHP User Manual fancyconfiguration.html#ini.include-path>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 are experiencing problems with reading and writing to files and youre using the server module version of PHP, remember to make sure that the files and directories youre 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:datainfo.txt", "r");
See fclose(), fsockopen( ), socket_set_timeout(), and popen().

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532342.htmlTechArticlefopen (PHP 3, PHP 4 >= 4.0.0)fopen -- Open file or URL description int fopen ( string filename, string mode [, int use_include_path]) If filename starts with "http://" (case insensitive...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn