PHP4 User manual: Function-fopen_php Tutorial

Source: Internet
Author: User
Tags ftp connection
fopen
(PHP 3, PHP 4 >= 4.0.0) fopen--open file or URL description
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 HTTP GET mode, and the file pointer points to the beginning of the returned server response file. A host with the base name of the requesting virtual Host: the header is sent.
Note that this file pointer allows you to re-retrieve the response of the body: You cannot use this function to access the HTTP response header.
The 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 this server does not support passive FTP mode, the error will be lost. You can go through FTP to open the file for either reading or writing (but not both).
If filename is "Php://stdin", "php://stdout", or "php://stderr" one of them, then the corresponding input and output stream will be opened. (This was introduced in PHP 3.0.13; In earlier versions, this file was called "/dev/stdin" or "/dev/fd/0" to access the input and output streams).
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 one of the following:
R-read-only open, pointer pointing to the beginning of the file;
r+-Open for Read and write, pointer pointing to file start;
W-write-only open, the pointer points to the beginning of the file, and the file size is zeroed. If the file does not exist, it is new;
w+-Open for Read and write, pointer to file start, file size zeroed. If the file does not exist, it is new;

A-for Append open, the pointer points to the end of the file. If the file does not exist, try to create it;
A +-opens for read and write, pointing to the end of the file. If the file does not exist, try to create a new.
Note: Mode can contain the letter B. This is only useful if the system distinguishes between binary and text files. (i.e. Windows. It is useless in Unix). If it is not needed, it will be ignored.
If you want to search for files in the website Building server script class \phpphp user manual 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.p hp.net/"," R "); $fp = fopen (" ftp://user:password@example.com/"," w ");
If you is experiencing problems with reading and writing to files and youre using the server module version of PHP, Remem ber to make sure the files and directories youre using is accessible to the server process.
On the Windows platform, is 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 ().

http://www.bkjia.com/PHPjc/532342.html www.bkjia.com true http://www.bkjia.com/PHPjc/532342.html techarticle fopen (PHP 3, PHP 4 >= 4.0.0) fopen--open file or URL description int fopen (string filename, string mode [, int use_include_path]) If filename starts with "http://" (case insensitive ...)

  • 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.