Check Filesize Of Remote File Using PHP

November 28, 2007 | PHP

This script is used to check filesize for a file located on a remote (far away) web server.

< ?php
function get_remote_size($url){
	$uh = curl_init();
	curl_setopt($uh, CURLOPT_URL, $url);

	// set NO-BODY to not receive body part
	curl_setopt($uh, CURLOPT_NOBODY, 1);

	// set HEADER to be false, we don't need header
	curl_setopt($uh, CURLOPT_HEADER, 0);

	// retrieve last modification time
	curl_setopt($uh, CURLOPT_FILETIME, 1);
	curl_exec($uh);

	// assign filesize into $filesize variable
	$filesize = curl_getinfo($uh,CURLINFO_CONTENT_LENGTH_DOWNLOAD);

	// assign file modification time into $filetime variable
	$filetime = curl_getinfo($uh,CURLINFO_FILETIME);
	curl_close($uh);

	// push out
	return array("size"=>$filesize,"time"=>$filetime);
}
// You can use it as follow:
print_r(get_remote_size("http://downloads.videolan.org/pub/videolan/vlc/0.8.6c/win32/vlc-0.8.6c-win32.exe"));
?>

Hope it’s cool ^_^

1 comment

This post has one comment

  1. Rajiva 09/04/2011 at 22:07

    Thank’s. This post very pretty and usable.

 

Leave a comment

Allowed tags are: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 



Switch to our mobile site