} else { $file = substr($file, $pos); } } } $file = $fileDirectory . $file; if (!$fileFilter->isValid($file)) { throw new IllegalArgumentException("File was not accepted by the server for tracking."); } // Everything's fine let's lookup the .torrent in the cache if needed: $cache_args = "file=" . $file . "&modtime=" . $fileModTime; $cacheddata = get_cached_data(TORRENT_CACHE_TTL, $cache_args); if ($cacheddata) { //If we have got the data in cache $torrent = unserialize($cacheddata); // use the cached data } else { //if not do queries etc to generate new data for ($i = 0; $i < sizeof($webseeds); $i++) { $realWebseeds[] = $webseeds[$i] . substr($file, strlen($fileDirectory)); } $torrent = new Torrent($file, $trackerURL, $realWebseeds); $torrent->ensureSHA1Loaded(); db_init(); $torrent->register(); set_cache_data(serialize($torrent), $cache_args); //save data in cache } header("Content-type: application/x-bittorrent"); header("Content-Disposition: attachment; filename=\"" . basename($file) . ".torrent\""); echo $torrent->toEncoded();