Helpful Information
 
 
Category: Programming Languages
Getting filesize of a remote file

Hi guys and gals.

Im wondering if its possible to retrieve the filesize of a remote file without having to download the whole file from my script.

Any help would be much appreciated.


Basil

Its ok, the problem has been solved.

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by 'tantrum:
Its ok, the problem has been solved.[/quote]

but how ? http://www.devshed.com/Talk/Forums/smile.gif

ok heres the solution..

$imgPath = '/foo/bar.gif'; // remote location
$imgHost = "www.foo.com";
$fp = fsockopen($imgHost, 80, &$errno, &$errstr, 30);
if(!$fp) {
echo "ERROR: $errno: $errstr";
} else {
fputs($fp,"HEAD $imgPath HTTP/1.0nHost: $imgHostnn");
while(!feof($fp)) {
$response .= fgets($fp,128);
}
fclose($fp);
}
$imgSz = ereg_replace("(.*)(Content-Length: )([0-9]*)(.*)","3",$response);

This is an extract of some code i found.
This works with all types of files...but I have been told it doesnt work with ALL remote servers.

Basil










privacy (GDPR)