PHP fpassthru() 函數(shù)

2018-11-21 16:07 更新

PHP fpassthru() 函數(shù)


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

定義和用法

fpassthru() 函數(shù)從打開文件的當(dāng)前位置開始讀取所有數(shù)據(jù),直到文件末尾(EOF),并向輸出緩沖寫結(jié)果。

該函數(shù)返回傳遞的字符數(shù),如果失敗則返回 FALSE。

語法

fpassthru(file)

參數(shù) 描述
file 必需。規(guī)定要讀取的打開文件或資源。


提示和注釋

注釋:當(dāng)在 Windows 系統(tǒng)的二進(jìn)制文件中使用 fpassthru() 函數(shù)時,請牢記,必須以二進(jìn)制的模式打開文件。

提示:如果您已經(jīng)向文件寫入數(shù)據(jù),就必須調(diào)用 rewind() 來將文件指針指向文件頭。

提示:如果您只想將文件的內(nèi)容輸出到輸出緩沖,而不對它進(jìn)行修改,請使用 readfile() 函數(shù)代替,這樣可以省去 fopen() 調(diào)用。


實例 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 指示被傳遞的字符數(shù)。


實例 2

轉(zhuǎn)儲 www 服務(wù)器的索引頁:

<?php
$file = fopen("http://www.example.com","r");
fpassthru($file);
?>


PHP Filesystem 參考手冊 完整的 PHP Filesystem 參考手冊
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號