【问题标题】:file_get_contents(): Filename cannot be empty in ubuntufile_get_contents():ubuntu 中文件名不能为空
【发布时间】:2021-07-26 00:49:17
【问题描述】:

这是我的功能,它可以在我的计算机上运行,​​但是当我在 DigitalOcean Ubuntu 服务器上运行它时,它给了我file_get_contents(): Filename cannot be empty 错误

public function uploadFile($request)
{
    $imageName = time() . '.' . $request->file('profile_photo')->getClientOriginalExtension();
    $image = $request->file('profile_photo');
    Storage::disk('s3')->put($imageName, file_get_contents($request->file('profile_photo')), 'public');
    return $imageName;
}

【问题讨论】:

  • 您尝试过什么解决问题的方法?
  • 我尝试了多种方法,但都没有奏效。我从我现有的项目中复制了这段代码,它甚至可以在我的本地机器上工作,但不能在数字海洋 ububntu 服务器上工作。我觉得有些配置问题
  • 我也有同样的问题。它可能是一些配置问题。 File_get_contents 在 digitalocean ubuntu 服务器上返回空。它在我的 localhost 和 namecheap 主机上运行良好。我现在正在将我的网站迁移到 namecheap。您可能应该尝试其他托管公司。

标签: laravel ubuntu digital-ocean


【解决方案1】:

考虑使用这种结构来存储照片:

public function uploadFile($request)
{
    $imageName = time() . '.' . $request->file('profile_photo')->getClientOriginalExtension();

    $path = $request->profile_photo->storeAs('public', $imageName, 's3');

    return $imageName;
}

文档:https://laravel.com/docs/8.x/requests#storing-uploaded-files

【讨论】:

  • 请分享更多详细信息,以便其他人可以从您的回答中学习 - 您改变了什么,为什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-19
  • 2017-06-15
相关资源
最近更新 更多