Fopen
(PHP 3, PHP 4> = 4.0.0) FOPEN - Open file or URL
description
INT fopen (string filename, string mode [, int us_include_path])
If FileName starts with "http: //", this function opens the specified server with the HTTP 1.0 connection, which is used to request, the file pointer points to the returned server response file. Start. A 'Host:' header with the basic name of the request virtual host is sent.
Note that this file pointer allows you to resign the response: You cannot use this function to access the HTTP response head.
The HTTP handle cannot be redirected below PHP 4.0.5. Because of this, Directories Must Include Trailing Slashes.
If FileName starts with "ftp: //", a specified FTP connection server is turned on, returns a pointer to be requested. If this server does not support passive FTP mode, it will be lost. You can use FTP to read or write files (but you can't be both).
If FileName is "php: // stdin", "php: // stdout", or "php: // stderr" there is one of them, the corresponding input and output stream will be opened. (This is introduced in PHP 3.0.13; in earlier versions, this file name "/ dev / stdin" or "/ fd / 0" is used to access the input and output flow).
If FileName begins in another way, this file will be opened from the file system and returns a pointer to open the file.
Returns false if it fails.
Mode can be any of the following:
'r' - Read-only open, pointer points to the file; 'R ' - to the read and write, the pointer points to the file; 'W' - only open, the pointer points to the file, the file size is clear. If the file does not exist, new; 'w ' - open to read and write, the pointer points to the file, the file size is cleared. If the file does not exist, then create; 'a' - to append, the pointer points to the end of the file. If the file does not exist, try new; 'A ' - Open to read and write, the pointer points to the end of the file. If the file does not exist, try to create new.
Note: MODE can contain letters 'b'. This is only useful in the system distinguish between binary and text files. (i.e. Windows. It is useless in UNIX). It will be ignored if it is not required.
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 ()
$ 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 experience 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 ().