Skip to content

Instantly share code, notes, and snippets.

@gaffling
Created March 31, 2021 13:42
Show Gist options
  • Save gaffling/3230768ff6ea607e43de3a27ff57744d to your computer and use it in GitHub Desktop.
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
/* ------------------------------------------------------------------------------------------- */
/* [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