function uploadTorrent(&$file) { if (!preg_match("#\\.torrent\$#", $file['name'])) { $error = Lang::$uploadTorrent['upload_wrong_extension']['fr']; } if ($file['type'] != "application/x-bittorrent") { $error = Lang::$uploadTorrent['upload_wrong_mime']['fr']; } if ($file['size'] > 10000000) { $error = "Le fichier torrent ne doit pas dépasser les 10Mo"; } if ($file['error'] > 0) { $error = "Erreur durant l'upload"; } if (strlen($file['name']) > 255) { $error = "Le nom du fichier est un peu long non ?"; } if (isset($error)) { @unlink($file["tmp_name"]); throw new MyException($error); } $path = createAndWriteToRandomFile(file_get_contents($file["tmp_name"])); @unlink($file["tmp_name"]); return $path; }
private function handleDownloadTorrentResponse($id, $infos, $response) { if ($infos['http_code'] != 200) { throw new MyException(Lang::$lang['api_t411server_error']['fr'], self::T411SERVER_ERROR); } $content_parsed = json_decode($response, true); if (!empty($content_parsed) && is_array($content_parsed)) { if (array_key_exists("error", $content_parsed)) { if ($content_parsed["code"] == 1301) { throw new MyException(Lang::$api['api_torrent_not_found']['fr'], self::TORRENT_NOT_FOUND); } } } return createAndWriteToRandomFile($response); }