php - Laravel 5.2 多个 file_get_contents() 不适用于产品

标签 php apache laravel amazon-s3

我有一个表单,可以在表单的不同部分接受多个图像( Logo 、封面、缩略图)。我正在尝试将这些上传到 Amazon s3。在我的 Controller 中:

public function store(Request $request){

  Storage::disk('s3')->put(
    $request->user()->id.'/thumbnail.png',
    file_get_contents($request->file('thumbnail')),
    'public'
  );
  Storage::disk('s3')->put(
    $request->user()->id.'/cover.png',
    file_get_contents($request->file('cover')),
    'public'
  );
  Storage::disk('s3')->put(
    $request->user()->id.'/logo.png',
    file_get_contents($request->file('logo')),
    'public'
  );

}

我能够在本地主机上上传和获取此上传图像的 URL,但在生产环境(带有 LAMP 的 Amazon linux 实例)上出现“file_get_contents:文件名不能为空错误”。我做错了什么?

最佳答案

您应该始终检查文件是否已上传:

if ($request->hasFile('thumbnail'))
   Storage::disk('s3')->put(
        $request->user()->id.'/thumbnail.png',
        file_get_contents($request->file('thumbnail')),
        'public'
   );
}

https://laravel.com/docs/5.3/requests#files

关于php - Laravel 5.2 多个 file_get_contents() 不适用于产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41125182/

相关文章:

javascript - Jquery 中的可拖动项目

javascript - 如何通过javascript执行php

linux - CentOS 7 Apachect1 移除虚拟主机

Laravel - 播种多对多关系

php - Homebrew安装的两个版本的icu4c

php - 保存产品自定义字段并将其显示在购物车页面中

python - 我可以在同一台计算机上运行两个 Web 服务器吗?

linux - apache2 www-data 下的多个实例

php - Laravel 5.6 Eager Loading 特定列不返回任何内容

php artisan Schedule :run, 没有计划的命令准备好运行,不知道为什么?