Question

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.

Was it helpful?

Solution

You can use file_get_contents() as an alternate solution..

<?php
$filename='something';
file_put_contents($filename,file_get_contents($url));
$size = getimagesize($filename);
var_dump($size);

OTHER TIPS

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.

<?php

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top