PHP fpassthru() 函數
完整的 PHP Filesystem 參考手冊
定義和用法
fpassthru() 函數從打開文件的當前位置開始讀取所有數據,直到文件末尾(EOF),并向輸出緩沖寫結果。
該函數返回傳遞的字符數,如果失敗則返回 FALSE。
語法
參數 | 描述 |
file | 必需。規定要讀取的打開文件或資源。 |
提示和注釋
注釋:當在 Windows 系統的二進制文件中使用 fpassthru() 函數時,請牢記,必須以二進制的模式打開文件。
提示:如果您已經向文件寫入數據,就必須調用 rewind() 來將文件指針指向文件頭。
提示:如果您只想將文件的內容輸出到輸出緩沖,而不對它進行修改,請使用 readfile() 函數代替,這樣可以省去 fopen() 調用。
實例 1
<?php
$file = fopen("test.txt","r");
// Read first line
fgets($file);
// Send rest of the file to the output buffer
echo fpassthru($file);
fclose($file);
?>
上面的代碼將輸出:
There are three lines in this file.
This is the last line.59
59 指示被傳遞的字符數。
實例 2
轉儲 www 服務器的索引頁:
<?php
$file = fopen("http://www.example.com","r");
fpassthru($file);
?>
完整的 PHP Filesystem 參考手冊