【发布时间】:2017-06-13 12:34:49
【问题描述】:
上传图片时,getRealPath() 总是返回false:
$image_file = $request->file('image_file');
$image_file->getRealPath(); // ---> FALSE
这是dd($image_file);的结果:
另外,当我尝试将它与图像干预一起使用时:
$image_file = $request->file('image_file');
Image::make($image_file->getRealPath())->.....
我收到以下错误:
AbstractDecoder.php 第 323 行中的 NotReadableException:图像源不是 可读
显然是因为getRealPath()返回false...有人已经问过这个问题了:getRealPath returning false (Image Intervention and Laravel 5.1)...但是没有解决办法。
你知道为什么会这样吗,我该如何解决这个问题?
【问题讨论】:
-
你的图片大吗?如果有帮助,请查看此答案stackoverflow.com/questions/25929197/…
-
@Vikash 不,图像大小是 16kb,所以不,这不是问题。
-
@PeraMika 您是否尝试过(就像您链接的帖子中的那个人)避免使用
getRealPath()方法并改用public_path()方法?这应该可以解决您的问题。 -
@Mihailo 是的,像这样:
$request->file('image_file')->public_path()我得到 方法 public_path 不存在。。 -
你不能“链”。请改用
public_path($request->file('image_file')->getClientOriginalName())。
标签: php laravel file-upload laravel-5.2 enctype