<?
# url - URL to retrieve
# timeout - seconds between each refresh, default 300, or 5 minutes
$subject $HTTP_POST_VARS['url'];
function 
get_remote_file($url$timeout 300) {
    
# on Windows, either change the dir name or make /tmp
    
$cached_name '/tmp/'.sha1($url).'cachedwebfile';
    if (!
file_exists($cached_name) or
    ((
time() - filemtime($cached_name)) > $timeout)) {
        
$f fopen($cached_name"wb");
        
flock($fLOCK_EX);
        
$ch curl_init($url);
        
curl_setopt($chCURLOPT_HEADER0);
        
curl_setopt($chCURLOPT_FILE$f);
        
curl_exec($ch);
        
curl_close($ch);
        
fclose($f);
    }
    
$f  fopen($cached_name"rb");
    
flock($fLOCK_SH);
    
$retval fread($ffilesize($cached_name));
    
fclose($f);
    return 
$retval;
}

if (
strlen($url) > 0) {
    
$filename explode("/"$url);
    
header('Content-type: application/octet-stream');
    
header('Content-Disposition: attachment; filename="' urldecode($filename[sizeof($filename) - 1]) . '"');
    
print_r(get_remote_file($url));
} else {
?>
<html>
<head>
<title>File Downloader</title>
<body>
        <form action="<? $_SERVER['PHP_SELF'?>" method="post">
            <p><b>File Downloader</b></p>
            <p>Please enter the URL of a file to download.</p>
            <div><input type="text" name="url" size="50" value="<? echo stripslashes($useraddress); ?>" /></div>
            <div><br /><input type="submit" value="Download" /></div>
        </form>
</body>
</html>
<? 
}
?>