Home Backend Development PHP Tutorial PHP4用户手册:函数-fopen_PHP

PHP4用户手册:函数-fopen_PHP

Jun 01, 2016 pm 12:39 PM
fopen function start manual Open pointer document user

手册

H1>

(PHP 3, PHP 4 >= 4.0.0)

fopen -- 打开文件或URL

描述

 

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

 

如果filename 以"http://"开始 (大小写不敏感), 则本函数用HTTP 1.0连接打开指定的服务器,这个页面被使用HTTP GET模式来请求,文件指针指向被返回的服务器响应文件的起始处。一个带有请求虚拟主机的基本名字的'Host:'头被发送。

注意,这个文件指针允许你重新找回响应的the body :你不能使用这个函数存取 HTTP 响应头。

在PHP 4.0.5以下不能重定向HTTP句柄。 Because of this, directories must include trailing slashes.

如果filename 以"ftp://"开始 (大小写不敏感),一个指定的ftp连接服务器被打开,返回一个被请求文件的指针。如果这个服务器不支持被动ftp模式,将发失错误。你可以经过ftp任意的为读或写打开文件(但不能两者不能同时)。

如果filename 是 "php://stdin", "php://stdout", 或 "php://stderr"其中之一,则相应的输入输出流将被打开地。  (这是在PHP 3.0.13中引入的;在早期版本中,这个文件名象 "/dev/stdin" 或 "/dev/fd/0"这样去使用来访问输入输出流)。

如果filename 是以别的方式开始的,这个文件将被从文件系统中打开,返回一个打开文件的指针。

如果打开失败,则返回FALSE。

mode 可以为下面任何一个:

 

'r' - 只读打开,指针指向文件开始;

'r+' - 为读写打开,指针指向文件开始;

'w' - 只写打开,指针指向文件开始,文件大小清零。如果文件不存在,则新建;

'w+' - 为读写打开,指针指向文件开始,文件大小清零。如果文件不存在,则新建;

'a' - 为追加打开,指针指向文件结尾。如果文件不存在,尝试新建;

'a+' - 为读写打开,指针指向文件结尾。如果文件不存在,尝试新建。

注意: mode 可以包含字母 'b'。这仅仅在在系统区分二进制和文本文件才有用。 (i.e. Windows. 它在Unix中是无用的)。如果不需要,它将被忽略。

如果你想在include_path中搜索文件,你可以使用可选的第三个参数并把它设置为"1"。


例1. fopen() 例

$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");

 

参见 fclose(), fsockopen(), socket_set_timeout(), 和 popen().

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

C++ Function Exception Advanced: Customized Error Handling C++ Function Exception Advanced: Customized Error Handling May 01, 2024 pm 06:39 PM

Exception handling in C++ can be enhanced through custom exception classes that provide specific error messages, contextual information, and perform custom actions based on the error type. Define an exception class inherited from std::exception to provide specific error information. Use the throw keyword to throw a custom exception. Use dynamic_cast in a try-catch block to convert the caught exception to a custom exception type. In the actual case, the open_file function throws a FileNotFoundException exception. Catching and handling the exception can provide a more specific error message.

In-depth analysis of pointers and references in C++ to optimize memory usage In-depth analysis of pointers and references in C++ to optimize memory usage Jun 02, 2024 pm 07:50 PM

By using pointers and references, memory usage in C++ can be optimized: Pointers: store addresses of other variables and can point to different variables, saving memory, but may generate wild pointers. Reference: Aliased to another variable, always points to the same variable, does not generate wild pointers, and is suitable for function parameters. Optimizing memory usage can improve code efficiency and performance by avoiding unnecessary copies, reducing memory allocations, and saving space.

How to return pointer in golang? How to return pointer in golang? Apr 23, 2024 pm 02:09 PM

Returning pointers in Go allows direct access to raw data. The syntax for returning a pointer is to use an asterisk prefixed type, for example: funcgetPointer()int{varxint=10;return&x}. Pointers can be used to dynamically allocate data, using the new function and dereferencing the pointer to set the value. Return pointers should pay attention to concurrency safety, aliasing and applicability.

Things to note when Golang functions receive map parameters Things to note when Golang functions receive map parameters Jun 04, 2024 am 10:31 AM

When passing a map to a function in Go, a copy will be created by default, and modifications to the copy will not affect the original map. If you need to modify the original map, you can pass it through a pointer. Empty maps need to be handled with care, because they are technically nil pointers, and passing an empty map to a function that expects a non-empty map will cause an error.

See all articles