PHP4 User manual: Function-fopen

Source: Internet
Author: User
Tags manual ftp ftp connection stdin
H1>
(PHP 3, PHP 4 >= 4.0.0)
Fopen--Open a file or URL
Describe

int fopen (string filename, string mode [, int use_include_path])

If filename starts with "http://" (case insensitive), this function opens the specified server with an HTTP 1.0 connection, which is requested using the HTTP GET mode, and the file pointer points to the beginning of the returned server response file. A ' host: ' Header with the basic name of the requesting virtual host is sent.
Note that this file pointer allows you to retrieve the body of the response: You cannot use this function to access the HTTP response header.
You cannot redirect HTTP handles 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 this server does not support passive FTP mode, the error will be lost. You can go through FTP to open files for reading or writing (but not both).
If filename is "Php://stdin", "php://stdout", or "php://stderr" one of them, the corresponding input output stream will be opened.
(This is 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 output stream).
If filename is started in a different way, the file will be opened from the file system, returning a pointer to the open file.
Returns False if the open fails.
Mode can be any of the following:

' R '-read-only open, the pointer points to the beginning of the file;
' r+ '-open for Read and write, pointer to file start;
' W '-write only open, pointer to file start, file size clear zero. If the file does not exist, the new;
' w+ '-open for Read and write, pointer to file start, file size clear zero. If the file does not exist, the new;
' A '-opens for append, pointing to end of file. If the file does not exist, try new;
' A + '-opens for reading and writing, and the pointer points to the end of the file. If the file does not exist, try new.
Note: Mode can contain the letter ' B '. This is only useful when the system distinguishes between binary and text files.
(i.e. Windows. It is useless in Unix). It will be ignored if it is not needed.
If you want to search for files in include_path, you can use the optional third argument and set it to "1".
Example 1. fopen () case
$fp = fopen ("/home/rasmus/file.txt", "R");
$fp = fopen ("/home/rasmus/file.gif", "WB");

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.