Fopen
Open a file or URL.
Syntax:Int fopen (string filename, string mode );
Return Value: integer
Function Type: File Access
Note: this function can be used to open local or remote files. If the filename parameter is "http: //...", this function uses the HTTP 1.0 protocol to connect to the server. The file pointer indicates the starting position of the file returned by the server. If filename is set to "ftp: // ......", this function is connected to the server. The file pointer is directed to the specified file. If the FTP server does not support passive mode FTP, a failure value is returned. The opened FTP file can be read or written to one of them, but cannot be read or written at the same time. In other cases, this function opens a local file, and the file Pointer Points to the opened file. If the file fails to be opened, false is returned.
The mode parameter of the string can be the following:
- 'R' indicates that the file is read-only, and the file Pointer Points to the beginning.
- 'R + ': the file can be read and written, and the file Pointer Points to the beginning.
- 'W' indicates writing in the open file mode. The file Pointer Points to the start point and sets the length of the original file to 0. If the file does not exist, create a new file.
- The 'W + 'Open file method can be read/write, the file Pointer Points to the start, and the length of the original file is set to 0. If the file does not exist, create a new file.
- 'A file is written in open mode, and the file Pointer Points to the end of the file. If the file does not exist, create a new file.
- 'A + 'can be used to open a file. The file Pointer Points to the end of the file. If the file does not exist, create a new file.
- 'B' this parameter can be used if the operating system text and binary file are different. This parameter is not required for UNIX systems.
The first behavior is UNIX system usage. The second line is Windows system usage. The third and fourth lines are examples of URL usage.
<?
$ Fp = fopen ("/home/Rasmus/file.txt", "R ");
$ Fp = fopen ("C: // mydata // info.txt", "R ");
$ Fp = fopen ("http://www.php.net/", "R ");
$ Fp = fopen ("ftp: // User: password@my.com/", "W ");
?>
Fclose () popen () fsockopen ()