其他分享
首页 > 其他分享> > get_headers()获取文件大小,解决https链接报错问题

get_headers()获取文件大小,解决https链接报错问题

作者:互联网

获取文件大小代码

$file_size = @get_headers($file_path, 1);
$file_size = $file_size['Content-Length'] ?? 0;

获取https的链接时报错日志

error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
[ error ] [2]get_headers(): Failed to enable crypto
[ error ] [2]get_headers(https://wvideo.haier.com/746efc9-17de531009e.mp4): failed to open stream: operation failed
[ error ] [2]get_headers(): SSL operation failed with code 1. OpenSSL Error messages:

解决方法

// 关闭https验证,不然get_headers不起作用
stream_context_set_default([
'ssl' => [
        'verify_host'      => false,
        'verify_peer'      => false,
        'verify_peer_name' => false,
    ],
]);
$file_size = @get_headers($file_path, 1);
$file_size = $file_size['Content-Length'] ?? 0;

标签:文件大小,https,get,verify,headers,报错,file,size
来源: https://blog.csdn.net/gongqinglin/article/details/122177210