【问题标题】:Laravel 5.3 Intervention/image NotReadableException using images from urlsLaravel 5.3 干预/图像 NotReadableException 使用来自 url 的图像
【发布时间】:2019-05-02 01:44:44
【问题描述】:

如何处理以下错误,以使我的脚本在异常发生时不会停止工作:

AbstractDecoder.php 第 302 行中的 NotReadableException:图像源不是 可读

我尝试过使用以下内容($file 是图片的 url):

// Return false if error
try
{
    $img = Image::make($file);
}
catch(NotReadableException $e)
{
    return false;
}

这似乎没有捕获异常并返回 false。我还能做什么?

【问题讨论】:

    标签: php exception-handling


    【解决方案1】:

    您要么需要捕获区域中的完整命名空间异常,要么在文件顶部添加该异常的 use 语句

    【讨论】:

    • 像 catch(Intervention\Image\Facades\Image NotReadableException $e) 之类的东西?
    • 不,不要使用外观 - 命名空间是 Intervention\Image\Exception\NotReadableException
    • 谢谢。刚刚在您发布回复时找到它;)
    • 忙于测试。一旦我知道它有效,我会接受你的回答。
    【解决方案2】:

    添加Intervention\Image\Exception\NotReadableException:

    use Intervention\Image\Exception\NotReadableException;
    
    try {
        //
    } catch(NotReadableException $e) {
        //
    }
    

    【讨论】:

      猜你喜欢
      • 2014-08-03
      • 2021-04-18
      • 1970-01-01
      • 2019-01-16
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      相关资源
      最近更新 更多