【问题标题】:Laravel file store returns tmp file nameLaravel 文件存储返回 tmp 文件名
【发布时间】:2019-04-09 03:54:32
【问题描述】:

简单的问题。我试图从表单帖子中将文件保存到存储中。代码:

$path = $request->file('image')->store('image');

$path 返回为/tmp/phpCCTWsV

如何解决这个问题?

【问题讨论】:

    标签: php laravel-5 storage


    【解决方案1】:

    当您提交表单时,所有文件都会保存到 tmp 文件夹中。然后,您必须将它们保存到存储中。例如:

    $disk = Storage::disk('local');
    $path = '/app/public/images/';
    $name = time().'.'.$image->getClientOriginalExtension();
    $disk->put(str_replace('/app', '', $path) . $name, $request->file('image'));
    $path .= $name; // This file's saved in `/storage/app/app/public/images/` folder
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多