成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? PHP:fread()的用法_Filesystem函數(shù)
全站頭部文字 我要出現(xiàn)在這里
PHP:fread()的用法_Filesystem函數(shù) 771 2023-12-15   

fread

(PHP 4, PHP 5)

fread — 讀取文件(可安全用于二進制文件)

說明

string fread ( resource $handle , int $length )

fread() 從文件指針 handle 讀取最多 length 個字節(jié)。 該函數(shù)在遇上以下幾種情況時停止讀取文件: 讀取了 length 個字節(jié) 到達了文件末尾(EOF) a packet becomes available or the socket timeout occurs (for network streams) if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size.

參數(shù)

handle

文件系統(tǒng)指針,是典型地由 fopen() 創(chuàng)建的 resource(資源)。

length

最多讀取 length 個字節(jié)。

返回值

返回所讀取的字符串, 或者在失敗時返回 FALSE

范例

Example #1 一個簡單的 fread() 例子

<?php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>

Example #2 Binary fread() example

Warning

在區(qū)分二進制文件和文本文件的系統(tǒng)上(如 Windows)打開文件時,fopen() 函數(shù)的 mode 參數(shù)要加上 'b'。

<?php
$filename = "c:\files\somepic.gif";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>

Example #3 Remote fread() examples

Warning

當(dāng)從任何不是普通本地文件讀取時,例如在讀取從遠程文件或 popen() 以及 fsockopen() 返回的流時,讀取會在一個包可用之后停止。這意味著應(yīng)該如下例所示將數(shù)據(jù)收集起來合并成大塊。

<?php
// 對 PHP 5 及更高版本
$handle = fopen("http://www.example.com/", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
?>
<?php
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);
?>

注釋

Note:

如果只是想將一個文件的內(nèi)容讀入到一個字符串中,用 file_get_contents(),它的性能比上面的代碼好得多。

Note:

Note that fread() reads from the current position of the file pointer. Use ftell() to find the current position of the pointer and rewind() to rewind the pointer position.

參見

fwrite() - 寫入文件(可安全用于二進制文件) fopen() - 打開文件或者 URL fsockopen() - 打開一個網(wǎng)絡(luò)連接或者一個Unix套接字連接 popen() - 打開進程文件指針 fgets() - 從文件指針中讀取一行 fgetss() - 從文件指針中讀取一行并過濾掉 HTML 標(biāo)記 fscanf() - 從文件中格式化輸入 file() - 把整個文件讀入一個數(shù)組中 fpassthru() - 輸出文件指針處的所有剩余數(shù)據(jù) ftell() - 返回文件指針讀/寫的位置 rewind() - 倒回文件指針的位置


主站蜘蛛池模板: 2024头像| coralie| 抖音网页抖音| 免费播放高清完整版电影| 敦君和女朋头| 挠中国美女丝袜脚心| 夜魔电影| 1和5阳性算不算很严重| 蜡笔小新日语| 托比·瑞格波| 辩论赛作文| 日本女人性生活视频| 不要好舒服| 性的秘密免费| 我的兴趣爱好| 极品美女在线| 最佳的一击电视剧全集免费| 无内秘书| 如果云知道歌词| 在线免费污视频| 来自地狱| 东方卫视节目表| 厕所英雄| 男骑女| 红蔷薇 电视剧| 对称度| 每天一分钱每天翻一倍连续30天| 三年片观看免费完整版中文版| 林海雪原演员表| 废纸板拳击手| 视频欧美| 浙江卫视网络直播源| 坏孩子电影| 洗冤录粤语| 梦的衣裳| 徐有容| 19岁女性写真| 免费完整队列训练教案| 视频污污| 经典伦理电影| 《求知报》答案|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103