【问题标题】:Laravel move() is not uploading images everytimeLaravel move() 不是每次都上传图片
【发布时间】:2019-01-06 20:10:53
【问题描述】:

我使用下面的代码:

$image_name = 'image' . time() . '.' . $request->file('image')->getClientOriginalExtension();
$destinationFolder = public_path('images');
$request->file('image')->move($destinationFolder, $image_name);

但有时它不工作,图像不存储。我使用 heroku 作为主机。

【问题讨论】:

  • 所以有时上传有时不上传?如果是这种情况,请尝试检查是否是名称冲突问题
  • 检查上传文件的大小,如果大于允许的最大值,则不会上传,因为问题不是来自应用程序,而是来自php

标签: php laravel file


【解决方案1】:

尝试使用Storage门面:

$path = \Storage::putFile('images', $request->file('image'));

Laravel 会自动生成一个名字,About Storage 门面,见this。 :)

【讨论】:

    【解决方案2】:

    我做了上传文件的功能,如果没有上传文件,再做一次,直到上传

        $imageFile->move($destinationFolder, $fileName);
        if(file_exists(public_path('images') . '/' . $fileName))
           return public_path('images') . '/' . $fileName;
        else
           self::uploadImage($imageFile, $fileName);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 2021-03-20
      • 1970-01-01
      相关资源
      最近更新 更多