Last active
December 3, 2018 13:31
-
-
Save YOzaz/6d3d73330eb28755cd4229018f1b40bf to your computer and use it in GitHub Desktop.
Check if image exists and compare file size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
stream_context_set_default( ['http' => ['method' => 'HEAD'] ] ); | |
$head = array_change_key_case( get_headers( $fullremotefilename, 1 ) ); | |
$content_length = isset($head['content-length']) ? (int)( $head['content-length'] ) : 0; | |
if ( $content_length ) { | |
$img_size = @filesize( $localfilename ); | |
if ( $img_size !== false && $img_size !== $content_length ) { | |
// images match! | |
} else { | |
// images don't match | |
} | |
} | |
// don't forget to reset default stream settings | |
stream_context_set_default( ['http' => ['method' => 'GET'] ] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment