PHP fpassthru() 函數

定義和用法
fpassthru() 函數從打開檔的當前位置開始讀取所有數據,直到檔末尾(EOF),並向輸出緩衝寫結果。
該函數返回傳遞的字元數,如果失敗則返回 FALSE。
語法
fpassthru(file)
參數 | 描述 |
---|---|
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);
?>
$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
This is the last line.59
59 指示被傳遞的字元數。
實例 2
轉儲 www 伺服器的索引頁:
<?php
$file = fopen("http://www.example.com","r");
fpassthru($file);
?>
$file = fopen("http://www.example.com","r");
fpassthru($file);
?>
