Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从文件上传解析JSON数据_Php_Json_Laravel_Laravel 5 - Fatal编程技术网

Php 从文件上传解析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

我有一个选择json文件的输入

在我的控制器里,我做到了

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?