public function __construct(User $user) { $this->user = $user; $torrentDB = new TorrentDB(); $fileDB = new FileDB(); foreach ($this->user->torrentHashes as $hash) { $torrent = $torrentDB->get($hash); $files = $fileDB->getTorrentFiles($torrent); foreach ($files as $file) { // If file is a "music" file if ($file->type == File::MUSIC_TYPE) { $this->process($file); } } } }
protected function txWriteData() { $this->encodeData(); if ($this->data !== $this->originalData) { return parent::txWriteData(); } return false; }
public static function init() { self::$conn = mysql_connect($GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass']); if (!self::$conn) { Util::log_and_die('Could not connect: ' . mysql_error()); } mysql_select_db($GLOBALS['dbname']); }
public static function entity($name) { $p = self::DB_PATH . $name . ".db"; if (!file_exists($p)) { if (!file_exists(dirname($p))) { mkdir(dirname($p), 0755, true); } $h = touch($p); } if (!empty(self::$entities[$name])) { $db = self::$entities[$name]; } else { $db = new FileDB($p); $db->readData(); self::$entities[$name] = $db; } return $db; }
public static function log_and_die($msg) { FileDB::close(); self::log($msg); die($msg); }
FileDB::init(); // duplication check if (FileDB::check_duplicate($md5_id)) { Util::log_and_die("Bad client upload request: duplicated file for " . $md5_id); } // type and size check $type = strtolower(pathinfo($file["name"], PATHINFO_EXTENSION)); $size = $_FILES['file']['size']; if ($size > MAXSIZE) { Util::log_and_die("Bad client upload request: file exceed size limit(" . MAXSIZE . "kb)"); } elseif (!in_array($type, $allowed_types)) { Util::log_and_die("Bad client upload request: unacceptable file format"); } // build upload path $upload_dir = "uploads/"; $ext = $type; $upload_path = $upload_dir . $md5_id . "." . $ext; // save the uploaded file to filesystem and add record to database $success = move_uploaded_file($file["tmp_name"], $upload_path) && FileDB::insert_record($upload_path, $from, $md5_id, $title, $category, $desc); if ($success) { } else { Util::log_and_die("Server error: upload failed"); } FileDB::close(); Util::log_and_echo("Request processed: file uploaded successfully"); // send the new file to peer servers $success = send_to_peers($upload_path, $md5_id, $title, $category, $desc); if (!$success) { Util::log("Response from peers: at least one peer didn't get the file"); } Util::log("Response from peers: all peers received the file successfully!");
$file = $fileDB->get($fileId); if (!is_null($file)) { ob_end_clean(); flush(); header('Content-Type: ' . $file->MIME_type); header('Content-Length: ' . $file->size); readfile($file->path); exit; } else { echo "File was not found"; } }); $app->get('/albumArtwork', function () use($app, $env) { $album = $app->request->params('album'); $artworkName = Music::ALBUM_ARTWORK_PATH . $album; $fileDB = new FileDB(); $artwork = $fileDB->getArtwork($artworkName); if ($artwork) { $file = $artwork[FileDB::ARTWORK_FILE]; $mime = $artwork[FileDB::ARTWORK_MIME]; $size = filesize($file); ob_end_clean(); flush(); header('Content-Type: ' . $mime); header('Content-Length: ' . $size); readfile($file); exit; } else { echo "Artwork not found"; } });
#!/usr/bin/php <?php ini_set("log_errors", 1); ini_set("extension", "mongo.so"); ini_set("error_log", "/tmp/php-error.log"); require_once '/var/www/torrentcloud/models/FileDB.php'; require_once '/var/www/torrentcloud/models/TorrentDB.php'; require_once '/var/www/torrentcloud/models/Torrent.php'; require_once '/var/www/torrentcloud/models/Helper.php'; require_once '/var/www/torrentcloud/models/File.php'; require_once '/var/www/torrentcloud/models/TorrentFile.php'; require_once '/var/www/torrentcloud/models/getid3/getid3.php'; $fileDB = new FileDB(); $torrentDB = new TorrentDB(); $torrentHash = getenv('TR_TORRENT_HASH'); $torrentData = $torrentDB->get($torrentHash); $torrent = new Torrent($torrentData); foreach ($torrent->files as $file) { $name = basename($file['name']); $extension = pathinfo($name, PATHINFO_EXTENSION); $path = $torrent->downloadDir . '/' . $file['name']; $finfo = finfo_open(FILEINFO_MIME_TYPE); $MIME_type = finfo_file($finfo, $path); $fileData = array(FileDB::TORRENT_HASH => $torrent->hashString, FileDB::NAME => $name, FileDB::EXTENSION => $extension, FileDB::SIZE => $file['length'], FileDB::PATH => $path, FileDB::MIME_TYPE => $MIME_type); $torrentFile = new TorrentFile($fileData); $torrentFile->analyze(); $fileDB->add($torrentFile); }
echo "This is not a valid registration link!"; return; } else { $user = new User($username); $user->registered = true; $user->update(); $_SESSION['AUTHED'] = true; $_SESSION['username'] = $username; $_SESSION['validTorrents'] = array(); $app->redirect("/"); } } else { echo "This is not a valid registration link!"; } }); $app->get('/file', $authenticateMiddleware, function () use($app, $env) { $fileDB = new FileDB(); $fileId = $app->request->params('id'); $file = $fileDB->get($fileId); if (!is_null($file)) { ob_end_clean(); flush(); header('Content-Type: ' . $file->MIME_type); header('Content-Length: ' . $file->size); readfile($file->path); exit; } else { echo "File was not found"; } }); $app->run();
<?php require_once "file_db.php"; // initiate db connection FileDB::init(); $records = FileDb::get_all_pictures(); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="description" content="Rapid start"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"> <title>Team Photo Sharing - CMPE 207</title> <link href='http://fonts.googleapis.com/css?family=Scada:400,400italic,700,700italic&subset=latin,cyrillic' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/demo.css"> <link rel="stylesheet" href="css/jquery.galereya.css"> <!--[if lt IE 9]> <link rel="stylesheet" href="css/jquery.galereya.ie.css"> <![endif]--> </head> <body> <div id="gal1"> <?php while ($row = mysql_fetch_array($records, MYSQL_ASSOC)) { echo ' <img src="' . $row["file_path"] . '"