$url='http://www.domain.com/files/file.zip';
$filename=basename($url);
$addy=parse_url($url);
$addy['port']=isset($addy['port'])?$addy['port']:80;
$sh=fsockopen($addy['host'],$addy['port']) or die('cant open socket');
fputs($sh,"HEAD {$addy['path']} HTTP/1.1\r\nHost: {$addy['host']}\r\n\r\n");
while($line=fgets($sh))
if(preg_match('/^Content-Length: (\d+)/',$line,$m))
$size=$m[1];
$s=my_filesize($size);
echo isset($size)?"The file $filename has a <b>$size</b> of size.":"The file $filename has an <b>unknown</b> size or no such file.";
}
This script works fine, but ONLY with simple urls, what should i do to get this code work with http server that required authentication? I mean like this:
$url='http://anyuser:anypass@www.domain.com/files/file.zip';
Give me sample code pls.
Thanks
Dedix