简体   繁体   English

“getimagesize(): SSL 操作失败,代码 1”仅在本地 Xampp 上

[英]"getimagesize(): SSL operation failed with code 1" on local Xampp only

getimagesize() fails in Xampp (local PC), although it works fine in the live environment. getimagesize() 在 Xampp(本地 PC)中失败,尽管它在实时环境中运行良好。

Based on the error message, the issue seems related to certificate configuration.根据错误消息,问题似乎与证书配置有关。 I have created self-signed certificates based on this article: https://shellcreeper.com/how-to-create-valid-ssl-in-localhost-for-xampp/我根据这篇文章创建了自签名证书: https : //shellcreeper.com/how-to-create-valid-ssl-in-localhost-for-xampp/

This removed the SSL warning from Apache's error log, but the issue with getimage() is still the same.这从 Apache 的错误日志中删除了 SSL 警告,但 getimage() 的问题仍然相同。

If I pass the image's URL with http instead of https , the call works.如果我使用http而不是https传递图像的 URL,则调用会起作用。

<?php
$file = "http://webtest.test/content/uploads/img.jpg";  // Will work
$file = "https://webtest.test/content/uploads/img.jpg"; // Will not work

// ...

$img_info = getimagesize($file);
if(!$img_info) {
  throw new Exception(__("The file type is not valid image (1)"));
}
?>

Error received:收到错误:

PHP Warning:  getimagesize(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in \\xampp\\htdocs\\index.php on line 3, referer: https://webtest.test/
PHP Warning:  getimagesize(): Failed to enable crypto in \\xampp\\htdocs\\index.php on line 3, referer: https://webtest.test/
PHP Warning:  getimagesize(https://webtest.test/content/uploads/photos/2019/08/2f203cfc1e.jpg): failed to open stream: operation failed in \\xampp\\htdocs\\index.php on line 3, referer: https://webtest.test/

Xampp/PHP version 7.3.6. Xampp/PHP 版本 7.3.6。 Loaded modules:加载的模块:

core mod_win32 mpm_winnt http_core mod_so mod_access_compat mod_actions mod_alias mod_allowmethods mod_asis mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_dav_lock mod_dir mod_env mod_headers mod_include mod_info mod_isapi mod_log_config mod_cache_disk mod_mime mod_negotiation mod_proxy mod_proxy_ajp mod_rewrite mod_setenvif mod_socache_shmcb mod_ssl mod_status mod_php7 

Where could the problem be coming from, and how to fix it ?问题可能来自哪里,如何解决?

如果您尝试从自己的服务器图像目录获取图像大小,则可以使用base_path而不是url().'pathtoyourimage'

将 CA 包添加到 Apache SSL 可以解决这个问题。

SSLCertificateChainFile /etc/apache2/ssl/My_CA_Bundle.ca-bundle

I had the same problem using the library html2pdf that needs to get the image size through the PHP function getsizeimage() and my image URL was with https so I solved by specifying in my php.ini file the SSL certificate. 我使用库html2pdf遇到了同样的问题,该库需要通过PHP函数getsizeimage()获取图像大小,而我的图像URL是https因此我通过在php.ini文件中指定SSL证书来解决。

[openssl]
openssl.cafile="/etc/nginx/tls/yourCert.crt"

Only one way correct!只有一种方式正确!

For apache2 + php: set to CAcerteficate in file php.ini -> [openssl] -> openssl.cafile= /etc/ssl/chain/YOURDOMAIN.COM/yourCAchain.crt对于 apache2 + php:在文件 php.ini -> [openssl] -> openssl.cafile= /etc/ssl/chain/YOURDOMAIN.COM/yourCAchain.crt 中设置为 CAcerteficate

When you get this error:当您收到此错误时:

getimagesize(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

You can solve it like so:你可以这样解决:

list($w,$h) = getimagesize(ROOTINDEX."admin/upload/post-images/".$value['post_image']);

So you can write this:所以你可以这样写:

list($w,$h) = (ROOTINDEX."admin/upload/post-images/".$value['post_image']);

And your code will be executed.你的代码将被执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TCPDF:getimagesize():SSL 操作失败,代码 1 错误:1416F086:SSL 例程:tls_process_server_certificate:证书验证失败 - TCPDF: getimagesize(): SSL operation failed with code 1 error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed APNS SSL操作失败,代码为1 - APNS SSL operation failed with code 1 GMail fsockopen():SSL 操作失败,Codeigniter 和 XAMPP 错误 - GMail fsockopen(): SSL operation failed error with Codeigniter and XAMPP get_headers():SSL 操作失败,代码为 1 - get_headers(): SSL operation failed with code 1 MAMP 和 PHP “SSL 操作失败,代码 1” - MAMP & PHP “SSL operation failed with code 1” SoapServer::SoapServer():SSL 操作失败,代码为 1 - SoapServer::SoapServer(): SSL operation failed with code 1 Laragon 下的 PHP - SSL 操作失败,代码为 1 - PHP under Laragon - SSL operation failed with code 1 SSL操作失败,代码为1 Whitt smtp - SSL operation failed with code 1 whit smtp 消息:imagecreatefrompng():SSL操作失败,代码为1 - Message: imagecreatefrompng(): SSL operation failed with code 1 WAMP/XAMPP 中的 SSL 错误:stream_socket_enable_crypto():SSL 操作失败 - SSL Error in WAMP/XAMPP: stream_socket_enable_crypto(): SSL operation failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM