skip to Main Content

getimagesize() fails in Xampp (local PC), although it works fine in the live environment.

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/

This removed the SSL warning from Apache’s error log, but the issue with getimage() is still the same.

If I pass the image’s URL with http instead of https, the call works.

<?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.
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 ?

4

Answers


  1. If you’re trying to get image size from your own servers images dir, you can use base_path instead of url().'pathtoyourimage'.

    Login or Signup to reply.
  2. Adding the CA bundle to Apache SSL fix this.

    SSLCertificateChainFile /etc/apache2/ssl/My_CA_Bundle.ca-bundle
    
    Login or Signup to reply.
  3. Only one way correct!

    For apache2 + php: set to CAcerteficate in file php.ini -> [openssl] -> openssl.cafile= /etc/ssl/chain/YOURDOMAIN.COM/yourCAchain.crt

    Login or Signup to reply.
  4. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search