最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
解决php中file_get_contents 读取大文件返回false问题
时间:2022-06-24 23:29:24 编辑:袖梨 来源:一聚教程网
如果我读取一个 www.111com.net文件
代码如下 | 复制代码 |
$u ='www.111com.net'; //此文件为100GB $a =file_get_contents( $u ); |
运行提示
Note: string can be as large as 2GB
不能大于2GB了,我们去官方看此函数参考
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
发现有个
file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败, file_get_contents() 将返回 FALSE。
原来如此,这样我们对程序进行修改即可
代码如下 | 复制代码 |
$u ='www.111com.net'; //此文件为100GB $a =file_get_contents( $u,100,1000 ); |
读取成功了
总结
file_get_contents如果正常返回,会把文件内容储存到某个字符串中,所以它不应该返回超过2G长度的字符串。
如果文件内容超过2G,不加offset和maxlen调用file_get_contents的话,肯定会返回false,
相关文章
- 炉石传说诈骗猎卡组构筑攻略 07-03
- 链圈:全球十大数字货币交易所按交易量排名2025年版 07-03
- Ripple首席执行官澄清Linqto与Ripple的关系及退款风波 07-03
- 幻想生活i转圈圈的龙和偷取时间的少女神祠位置一览 07-03
- SideShift-Token(XAI币)的客户端好用吗 XAI币快捷交易平台币安推荐 07-03
- 方块大陆九个兑换码分享 07-03