PHP4 User Manual: function-fopen

Source: Internet
Author: User
Tags ftp connection

Fopen
(PHP 3, PHP 4> = 4.0.0) fopen -- open the 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 with the basic name of the requesting VM: the header 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 +-for read/write access, the Pointer Points to the start of the file;
W-Write-only open: the Pointer Points to the beginning of the file, and 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 +-for read/write operations, the Pointer Points to the end of the file. If the file does not exist, try to create a new one.
Note: mode can contain letters B. 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 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 yousing 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 ().

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.