通过php中的字节数获取文件的一部分 [英] Get part of a file by byte number in php
本文介绍了通过php中的字节数获取文件的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ fp = fopen('somefile.txt','r');
//移动到第7个字节
fseek($ fp,7);
$ data = fread($ fp,8); //从字节7读取8个字节
fclose($ fp);
How can I have php return just some bytes of a file? Like, it I wanted to load byte 7 through 15 into a string, without reading any other part of the file? Its important that I don't need to load all of the file into memory, as the file could be quite large.
解决方案
$fp = fopen('somefile.txt', 'r');
// move to the 7th byte
fseek($fp, 7);
$data = fread($fp, 8); // read 8 bytes from byte 7
fclose($fp);
这篇关于通过php中的字节数获取文件的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文