【问题标题】:Convert from JSON formatted string to downloadable JSON file从 JSON 格式的字符串转换为可下载的 JSON 文件
【发布时间】:2014-10-03 01:15:33
【问题描述】:

我从一个数组开始:

$arr = array(
        0 => array(
            'name' => Input::get('symptom'),
            'amount' => 5,
            'time' => '2:00 am',
            'date' => '10.26.96',
            'type' => 'symptom',
        )

我把它保存给用户:

$user = Auth::user();
$user->json = json_encode($arr);

然后下载:

<form method="get" action="json.json">
    <button type="submit">Download!</button>
</form>

如何让用户下载Auth::user()-&gt;json?的内容 任何帮助表示赞赏!

PS 我正在使用 Laravel,但我不知道这是否重要。

【问题讨论】:

    标签: php html json laravel


    【解决方案1】:

    先创建一个文件,然后把这个路径如下

    $user = Auth::user();
    $user->json = json_encode($arr);
    $path = public_path('json.json');
    $file = File::put($path,$user->json);
    return Response::download($path);
    

    【讨论】:

    • 感谢您的回答。 pathToFile 来自哪里?
    猜你喜欢
    • 2023-01-20
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 2020-09-09
    • 2020-02-29
    • 1970-01-01
    相关资源
    最近更新 更多