只能读取文件的第一行 php
can read only first line of file php
我想读取来自输入的 .tsv 文件。但是只能获取到第一行。
dd($request->file) returns 这个:
-test: false
-originalName: "ürünler_2021-04-08_02-39-00.tsv"
-mimeType: "application/octet-stream"
-error: 0
#hashName: null
path: "C:\xampp\tmp"
filename: "php1D74.tmp"
basename: "php1D74.tmp"
pathname: "C:\xampp\tmp\php1D74.tmp"
extension: "tmp"
realPath: "C:\xampp\tmp\php1D74.tmp"
aTime: 2021-04-09 05:08:47
mTime: 2021-04-09 05:08:47
cTime: 2021-04-09 05:08:47
inode: 10133099161895727
size: 1987
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\xampp\tmp\php1D74.tmp"
}
并在循环中使用 fgets() 但我只能得到第一行
$request->validate([
'file' => 'required|max:2048',
]);
$file = fopen($request->file, "r");
if ($file) {
while (($line = fgets($file))) {
dd($line);
}
fclose($file);
}
发生这种情况是因为我尝试读取 .tsv 文件?
dd($line) 将 运行 dump() 然后 die()。这就是为什么你只得到第一行的原因。
如果要转储所有行的内容,切换到仅转储($line)。
我想读取来自输入的 .tsv 文件。但是只能获取到第一行。
dd($request->file) returns 这个:
-test: false
-originalName: "ürünler_2021-04-08_02-39-00.tsv"
-mimeType: "application/octet-stream"
-error: 0
#hashName: null
path: "C:\xampp\tmp"
filename: "php1D74.tmp"
basename: "php1D74.tmp"
pathname: "C:\xampp\tmp\php1D74.tmp"
extension: "tmp"
realPath: "C:\xampp\tmp\php1D74.tmp"
aTime: 2021-04-09 05:08:47
mTime: 2021-04-09 05:08:47
cTime: 2021-04-09 05:08:47
inode: 10133099161895727
size: 1987
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\xampp\tmp\php1D74.tmp"
}
并在循环中使用 fgets() 但我只能得到第一行
$request->validate([
'file' => 'required|max:2048',
]);
$file = fopen($request->file, "r");
if ($file) {
while (($line = fgets($file))) {
dd($line);
}
fclose($file);
}
发生这种情况是因为我尝试读取 .tsv 文件?
dd($line) 将 运行 dump() 然后 die()。这就是为什么你只得到第一行的原因。
如果要转储所有行的内容,切换到仅转储($line)。