PHP file_get_contents有限制吗?

Sco*_*ter 10 php file-get-contents large-files

我试图使用php file_get_contents读取一个大文件(10M)

$file = 'http://www.remoteserver.com/test.txt';
$data = file_get_contents( $file );
var_dump ( $data );
Run Code Online (Sandbox Code Playgroud)

它倾倒了

string(32720)
Run Code Online (Sandbox Code Playgroud)

然后输出只显示文件的一部分.file_get_contents的某处有限制吗?我试过做ini_set('memory_limit','512M'),但那没用.

编辑:**忘了提**它是一个远程文件.

问题已解决 ::硬盘空间不足.修正了现在一切正常.

Lix*_*Lix -1

假设您要加载的文件的内容在逻辑上由换行符分隔(例如:不是二进制文件),那么您最好逐行读取。

$fp = fopen($path_to_file, "r");  
$fileLines = array();
while (!feof($fp)){
  array_push(fgets($fp),$fileContents);
} 
fclose($$fp);
Run Code Online (Sandbox Code Playgroud)

如果您确实需要将文件放在一个“块”中,那么您始终可以implode()(通过选择换行符)将数组恢复为单个字符串。

参考 -