Check Filesize Of Remote File Using 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);
	// 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);
	// push out
	return array("size"=>$filesize,"time"=>$filetime);
// You can use it as follow:

Hope it’s cool ^_^


4 responses

  1. Thank’s. This post very pretty and usable.

  2. Pouchon Avatar

    Very useful. How do I format the output? Please advise.


  3. thanks

Leave a Reply

Verified by MonsterInsights