今天使用PHP下载远程图片,一直显示为空打开报错提示 readfile(): SSL operation fAIled with code 1. OpenSSL Error messages,接下来为大家介绍一下解决方法,有需要的小伙伴可以参考一下:

1、错误提示:

Warning: readfile(): SSL operation failed with code 1

2、解决方法:

    这个时候我们需要使用到了readfile的第三个参数,然后使用stream_context_create函数生成对应的资源流,参数代码如下:

$stream_opts = [
            "ssl" => [
                "verify_peer"=>false,
                "verify_peer_name"=>false,
            ]
        ];
$result = file_get_contents("https://www.itbiancheng.com/uploads/20191226/840f3f425c8e905d7b06125ab51ceeba.png", false, stream_context_create($stream_opts));

3、知识扩展:

    (1)、readfile语法:

readfile(filename,include_path,context) 

    (2)、readfile相关参数:

Warning: readfile(): SSL operation failed with code 1

    (3)、stream_context_create相关:

    创建并返回一个资源流上下文,该资源流中包含了 options 中提前设定的所有参数的值。 

 stream_context_create ([ array $options [, array $params ]] ) : resource

     PS:options必须是一个二维关联数组,格式如下:$arr['wrapper']['option'] = $value 。默认是一个空数组 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。