require ("url_filesize.inc");
if (isset($name) AND isset($ext))
{ $file="$name.$ext"; }
if (isset($file))
{
// Find out how big the file should be
// first search the table
$sqlstmt="SELECT contentlength FROM mir_Files WHERE UCASE(filename)=UCASE('$file')";
@$result=mysql_query($sqlstmt)
or die ("Could not select file!");
if (mysql_num_rows($result)>0)
{ $bytesize=mysql_result($result,0,"contentlength"); }
// if not in table, search johnwschlitt.com addresses & add to table
else
{
$sqlstmt="SELECT address FROM `mir_Sites` WHERE address LIKE '%johnwschlitt.com%'";
@$result=mysql_query($sqlstmt)
or die ("Could not select johnwschlitt.com locations!");
while ($row=mysql_fetch_assoc($result))
{
$bytesize=url_filesize($row["address"].$file);
if ($bytesize>0)
{
@$res=mysql_query("INSERT INTO mir_Files (filename, contentlength, added) VALUES ('$file', '$bytesize', NOW())")
or die ("Could not insert $file - $bytesize!");
}
}
}
// Now we know the correct size for the file, so we can look for a site
// that has it available
$sqlstmt="SELECT ID, sitename, siteurl, address FROM `mir_Sites` WHERE available>$bytesize OR allotted=999 ORDER BY lastaccess"; // List of sites with available bandwidth
@$result=mysql_query($sqlstmt)
or die("Could not get list of sites with available bandwidth!");
$found=false;
while ($row=mysql_fetch_assoc($result))
{
if (!$found)
{
$sbytesize=url_filesize($row["address"].$file);
if (number_format($sbytesize)==number_format($bytesize)) // Size is correct
{
// Show the link
print "Right-click and select \"Save Target As\"
to download $file (".ceil($bytesize/pow(1024,2))."mb)
";
if ($row["siteurl"]!="")
{ print "
Thanks to ".$row["sitename"]." for mirroring this file!
"; }
// Decrement available for the site
@$res=mysql_query("UPDATE mir_Sites SET available=available-$bytesize WHERE ID=".$row["ID"]." AND allotted<>999");
// Increment accesses for the site
@$res=mysql_query("UPDATE mir_Sites SET accesses=accesses+1 WHERE ID=".$row["ID"]);
// Increment accesses for the file
@$res=mysql_query("UPDATE mir_Files SET accesses=accesses+1 WHERE UCASE(filename)=UCASE('$file')");
$found=true; // so we don't show any more links
}
}
}
}
?>
close this window