PHP readfile() 函數


PHP Filesystem 參考手冊 完整的 PHP Filesystem 參考手冊

定義和用法

readfile() 函數讀取一個檔,並寫入到輸出緩衝。

如果成功,該函數返回從檔中讀入的位元組數。如果失敗,該函數返回 FALSE 並附帶錯誤資訊。您可以通過在函數名前面添加一個 '@' 來隱藏錯誤輸出。

語法

readfile(filename,include_path,context)

參數 描述
filename 必需。規定要讀取的檔。
include_path 可選。如果您還想在 include_path(在 php.ini 中)中搜索檔的話,請設置該參數為 '1'。
context 可選。規定檔句柄的環境。context 是一套可以修改流的行為的選項。


提示和注釋

提示:如果在 php.ini 檔中 "fopen wrappers" 已經被啟動,您可以在本函數中把 URL 作為檔案名來使用。


實例

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

上面的代碼將輸出:

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


PHP Filesystem 參考手冊 完整的 PHP Filesystem 參考手冊