Php 从文件上传解析JSON数据
我有一个选择json文件的输入 在我的控制器里,我做到了Php 从文件上传解析JSON数据,php,json,laravel,laravel-5,Php,Json,Laravel,Laravel 5,我有一个选择json文件的输入 在我的控制器里,我做到了 dd(Input::all()); 我得到 我的目标是解析我得到的JSON文件并循环遍历它们 我试过了 $string = file_get_contents(Input::get('fileinput')); $json = json_decode($string, true); 如何继续?Input::get用于从请求($\u请求)检索输入项, 您应该改用Input::file,它用于从请求中检索文件,并返回illumb\Htt
dd(Input::all());
我得到
我的目标是解析我得到的JSON文件并循环遍历它们
我试过了
$string = file_get_contents(Input::get('fileinput'));
$json = json_decode($string, true);
如何继续?
Input::get
用于从请求($\u请求)检索输入项,
您应该改用Input::file
,它用于从请求中检索文件,并返回illumb\Http\UploadedFile
实例
例如:
<?php
$file = Input::file('fileinput');
if($file === null) {
throw new Exception('File was not sent !');
}
if($file->isReadable()) {
$file->open('r');
$contents = $file->fread($file->getSize());
$json = json_decode($contents, true);
} else {
throw new Exception('File is not readable');
}
我做了这件事,它对我很有用
Input::file('fileinput')->move(public_path(), 'fortinet_logs.json');
$string = file_get_contents(public_path().'/fortinet_logs.json');
$json = json_decode($string, true);
我使用的是Laravel版本6,其他解决方案不起作用。以下几点对我很有用:
$file = request()->fileinput; // <input type="file" name="fileinput" />
$content = file_get_contents($file);
$json = json_decode($content, true);
$file=request()->fileinput;//
$content=file\u get\u contents($file);
$json=json_decode($content,true);
Input::get('fileinput')
返回什么?我不确定它为什么返回null
。我已经更新了我的答案,它现在应该可以工作了!我现在正在尝试。我一直得到null
什么确切地返回null?