$ExtraTmpFileList = array(); foreach ($ExtraFileList as $ExtraFile) { list($ExtraSize, $ExtraName) = $ExtraFile; check_file($Type, $ExtraName); // Make sure the file name is not too long if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) { $Err = "The torrent contained one or more files with too long of a name: <br />{$ExtraDirName}/{$ExtraName}"; break; } // Add file and size to array $ExtraTmpFileList[] = Torrents::filelist_format_file($ExtraFile); } // To be stored in the database $ThisInsert['FilePath'] = db_string($ExtraDirName); $ThisInsert['FileString'] = db_string(implode("\n", $ExtraTmpFileList)); $ThisInsert['InfoHash'] = pack('H*', $ExtraTor->info_hash()); $ThisInsert['NumFiles'] = count($ExtraFileList); $ThisInsert['TorEnc'] = db_string($ExtraTor->encode()); $ThisInsert['TotalSize'] = $ExtraTotalSize; $Debug->set_flag('upload: torrent decoded'); $DB->query("\n\t\tSELECT ID\n\t\tFROM torrents\n\t\tWHERE info_hash = '" . db_string($ThisInsert['InfoHash']) . "'"); if ($DB->has_results()) { list($ExtraID) = $DB->next_record(); $DB->query("\n\t\t\tSELECT TorrentID\n\t\t\tFROM torrents_files\n\t\t\tWHERE TorrentID = {$ExtraID}"); if ($DB->has_results()) { $Err = "<a href=\"torrents.php?torrentid={$ExtraID}\">The exact same torrent file already exists on the site!</a>"; } else { //One of the lost torrents. $DB->query("\n\t\t\t\tINSERT INTO torrents_files (TorrentID, File)\n\t\t\t\tVALUES ({$ExtraID}, '{$ThisInsert['TorEnc']}')"); $Err = "<a href=\"torrents.php?torrentid={$ExtraID}\">Thank you for fixing this torrent.</a>"; }
//--------------- Make variables ready for database input ----------------------// // Shorten and escape $Properties for database input $T = array(); foreach ($Properties as $Key => $Value) { $T[$Key] = "'" . db_string(trim($Value)) . "'"; if (!$T[$Key]) { $T[$Key] = null; } } //******************************************************************************// //--------------- Generate torrent file ----------------------------------------// $Tor = new BencodeTorrent($TorrentName, true); $PublicTorrent = $Tor->make_private(); // The torrent is now private. $TorEnc = db_string($Tor->encode()); $InfoHash = pack('H*', $Tor->info_hash()); $DB->query("\n\tSELECT ID\n\tFROM torrents\n\tWHERE info_hash = '" . db_string($InfoHash) . "'"); if ($DB->has_results()) { list($ID) = $DB->next_record(); $DB->query("\n\t\tSELECT TorrentID\n\t\tFROM torrents_files\n\t\tWHERE TorrentID = {$ID}"); if ($DB->has_results()) { $Err = '<a href="torrents.php?torrentid=' . $ID . '">The exact same torrent file already exists on the site!</a>'; } else { // A lost torrent $DB->query("\n\t\t\tINSERT INTO torrents_files (TorrentID, File)\n\t\t\tVALUES ({$ID}, '{$TorEnc}')"); $Err = '<a href="torrents.php?torrentid=' . $ID . '">Thank you for fixing this torrent</a>'; } } if (isset($Tor->Dec['encrypted_files'])) { $Err = 'This torrent contains an encrypted file list which is not supported here.'; }