【发布时间】:2016-12-25 22:25:28
【问题描述】:
我必须用 fopen 打开一个文件并阅读全部内容。 该文件可通过 ssh-sftp 连接访问:
这是我连接、打开和读取文件的代码:
//ssh connection
$connection = ssh2_connect($host, $port);
//open the file
$handle = fopen("ssh2.sftp://$sftp".$file, "r");
$out = array();
//read the file
while (($fields = fgetcsv($handle, 0, ";")) !== FALSE) {
$out[]=$fields;
}
该文件实际上是一个 csv 文件。使用 fgetcsv 我逐行读取文件。 但是,即使我的文件在大约 20 行之后有 50 行,fgetcsv 也会失败并且我的最终输出数组不完整。 该文件实际上是我机器上的本地文件:如果通过 ssh 打开,则仅读取前 20 行,如果使用直接文件系统路径正常打开:
fopen("localpath", "r");
while 循环读取所有 50 行。
从 ssh 连接读取时是否有字节限制?可以使用 php.ini 配置选项更改此限制吗?
【问题讨论】: