获取文件大小代码
$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;