Created
March 31, 2021 13:42
-
-
Save gaffling/3230768ff6ea607e43de3a27ff57744d to your computer and use it in GitHub Desktop.
[FileSize URL] Get FileSize of an URL without downloading the file #php #function #filesize
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
/* ------------------------------------------------------------------------------------------- */ | |
/* [FileSize URL] Get FileSize of an URL without downloading the file #php #function #filesize */ | |
/* ------------------------------------------------------------------------------------------- */ | |
function getRemoteFileSize($url) { | |
ini_set('user_agent', 'Mozilla/5.0'); | |
if (substr($url,0,4)=='http') { | |
$header = array_change_key_case(get_headers($url, 1), CASE_LOWER); | |
#echo'<pre>';var_dump($$header); | |
if ( strcasecmp($header[0], 'HTTP/1.1 200 OK') != 0 ) { | |
$header = $$header['content-length'][1]; | |
} else { | |
$header = $header['content-length']; | |
} | |
} else { | |
$$header = @filesize($url); | |
} | |
return $x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment