---
title: "readfile()"
author: "yangyz1984"
date: "2010-08-25T21:08:24Z"
tags: []
categories: ["编程语言"]
slug: "readfile"
draft: false
lastmod: "2010-08-25T21:08:24Z"
id: 747207
url: "https://yyzstudy.iteye.com/blog/747207"
---

## 定义和用法

readfile() 函数输出一个文件。

该函数读入一个文件并写入到输出缓冲。

若成功，则返回从文件中读入的字节数。若失败，则返回 false。您可以通过 @readfile() 形式调用该函数，来隐藏错误信息。

 

### 语法

```
readfile(filename,include_path,context)
```

参数 描述 filename 必需。规定要读取的文件。 include\_path 必需。如果也想在 include\_path 中搜索文件，可以使用该参数并将其设为 true。 context 必需。规定文件句柄的环境。Context 是可以修改流的行为的一套选项。

### 说明

对 *context* 参数的支持是 PHP 5.0.0 添加的。

## 提示和注释

提示：如果在 php.ini 文件中 "fopen wrappers" 已经被激活，则在本函数中可以把 URL 作为文件名来使用。

## 例子

```
<?php
echo readfile("test.txt");
?>
```

输出：

```
There are two lines in this file.
This is the last line.
57
```