PHP4 User Manual: function-fopen

Source: Internet
Author: User
Tags ftp connection
H1 (PHP3, PHP44.0.0) fopen -- open the file or URL description intfopen (stringfilename, stringmode [, intuse_include_path]). if filename starts with (case insensitive ), this function uses HTTP1.0 to connect to open the specified server. this page is requested in HTTPGET mode. the file pointer points to the manual.

H1>

(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 starts with "http: //" (case insensitive), this function uses HTTP 1.0 to connect to open the specified server. this page is requested in http get mode, the file pointer points to the start point of the response file of the returned server. A 'host: 'header with the basic name of the requesting VM is sent.

Note: This file pointer allows you to retrieve the body of the response again: you cannot use this function to access the HTTP response header.

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 the server does not support the Passive ftp mode, an error is returned. You can open a file for reading or writing through ftp (but not both ).

If filename is "php: // stdin", "php: // stdout", or "php: // stderr, the corresponding input and output streams are opened. (This was introduced in PHP 3.0.13; in earlier versions, this file name is used like "/dev/stdin" or "/dev/fd/0" to access the input/output stream ).

If filename starts in another way, the file will be opened from the file system and a pointer to open the file will be returned.

If it fails to be opened, FALSE is returned.

Mode can be any of the following:

'R'-read-only open, pointer pointing to file start;

'R + '-indicates that the read/write operation is enabled, and the pointer points to the start of the file;

'W'-Write-only open, pointer pointing to the beginning of the file, the file size is cleared. If the file does not exist, it is created;

'W + '-for read/write operations, the pointer points to the start of the file, and the file size is cleared. If the file does not exist, it is created;

'A'-for append opening, the pointer points to the end of the file. If the file does not exist, try to create a new one;

'A + '-open for read/write and point the pointer to the end of the file. If the file does not exist, try to create a new one.

Note: the mode can contain the 'B' letter '. This is useful only when binary and text files are distinguished by the system. (I. e. Windows. it is useless in Unix ). If not, it is ignored.

If you want to search for a file 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 are experiencing problems with reading and writing 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 ().

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.