Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to use getimagesize with URL and with http everything is fine. However when trying to use function on https url I am getting "Read error" Notice and false as result. I checked and I have OpenSSL 0.98 installed on the server (so it should be working with https as well). I know that I can download the image first and then use it but it seems to me like this should work and that I am missing something. Could you please provide me with some solution (other than downloading the image first and then opening it) ?

Thank you in advance.

Although it may be irrelevant for this (as there may be no check for that): Is the certificate of the domain you try to download from signed by an authority known to the system? Abrixas2 Apr 21, 2014 at 8:44 $filename='something'; file_put_contents($filename,file_get_contents($url)); $size = getimagesize($filename); var_dump($size); "other than downloading the image first and then opening it" I was hoping for some server || php configuration to resolve the issue... Goran Apr 21, 2014 at 9:02 @Goran, as an alternate solution.. that's what the answer says.. Will find a way for your problem. Shankar Narayana Damodaran Apr 21, 2014 at 9:05 The main problem is that getimagesize is used in third party library. That means if I change anything in it, first time anyone updates it with composer it will roll back. That is why I need to see why am I getting this error and if I fail to find the answer I will adjust my way of coding (download first and then give file path). Thank you for the alt answer though! Goran Apr 21, 2014 at 9:09

Using file_get_contents() only shifts the problem instead of solving it when you don't change any of SSL's settings. But you can achieve that thru stream_context_create and then fiddling with the SSL settings . Once you did that you're also able to pass what SSL wants to protect you from.

error_reporting( E_ALL ); header( 'Content-type: text/plain' ); // The remote file to check $sPic= 'https://picture.to/check/for/details.png'; // Does it work right away? $aInfo= @getimagesize( $sPic ); if( $aInfo=== FALSE ) { // No. Then a temporary file needs to be created. if( $sTmp= tempnam( sys_get_temp_dir(), 'sig' ) ) { // Tweaking the HTTPS options to weaken/ignore security $hCtx= stream_context_create ( array ( 'ssl'=> array ( 'verify_peer'=> FALSE // Certificate verification , 'verify_peer_name'=> FALSE , 'allow_self_signed'=> TRUE , 'SNI_enabled'=> TRUE // Multiple certificates on same IP address // Download file $sPayload= file_get_contents( $sPic, FALSE, $hCtx ); if( $sPayload!== false ) { // Success: write to temporary file if( file_put_contents( $sTmp, $sPayload ) ) { $aInfo= @getimagesize( $sTmp ); } else die( 'Could not write to tempfile!' ); } else die( 'Could not download file!' ); // Delete temporary file unlink( $sTmp ); } else die( 'Could not get tempfile name!' ); // Picture file details print_r( $aInfo );

Updating OpenSSL may solve your problem.

Judging from the OpenSSL version you report you have on server this problem may be caused by the server having a newer version of SSL than your client.

The Facebook server is probably using a version >= 1.0.0 or a custom SSL library, while you are using an old 0.9.8.

Heartbeat overflow issue forced many webservers to update their OpenSSL version.

A random article about OpenSSL 1.0.0 handshake issues with clients using 0.9.8 version:

https://groups.google.com/forum/#!topic/msysgit/jSOTOQXPnwU

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .