【发布时间】:2020-01-03 14:19:54
【问题描述】:
getimagesize() 在 Xampp(本地 PC)中失败,尽管它在实时环境中运行良好。
根据错误消息,问题似乎与证书配置有关。我根据这篇文章创建了自签名证书:https://shellcreeper.com/how-to-create-valid-ssl-in-localhost-for-xampp/
这从 Apache 的错误日志中删除了 SSL 警告,但 getimage() 的问题仍然相同。
如果我使用 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)"));
}
?>
收到错误:
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 版本 7.3.6。 加载的模块:
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
问题可能来自哪里,如何解决?
【问题讨论】:
-
更新您的 CA 包。很可能您遗漏了一个或它已过时。
-
假设链接文章中解释的操作具有由 Windows 生成和处理的 CA 包。我只是双击crt文件并按照步骤操作。在 php.ini 中,我读到“
If openssl.cafile is not specified or if the CA file is not found, the directory pointed to by openssl.capath is searched for a suitable certificate. This value must be a correctly hashed certificate directory. Most users should not specify a value for this directive as PHP will attempt to use the OS-managed cert stores in its absence.。也许问题出在那儿:-/
标签: php xampp getimagesize