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);
?>
完整的PHP Filesystem參考手冊