Файл: sys/system.files.php
Строк: 137
<?php
class Files {
function GetFilesCountByOwner($db, $owner) {
$sql = "SELECT id FROM files WHERE owner=$owner";
$res = $db->Query($sql, null);
$rows = mysql_num_rows($res);
return $rows;
}
function GetFilesCount($db) {
$sql = "SELECT id FROM files";
$res = $db->Query($sql, null);
$rows = mysql_num_rows($res);
return $rows;
}
function GetFilesCountByCategory($db, $category) {
$sql = "SELECT id FROM files WHERE category='$category'";
$res = $db->Query($sql, null);
$rows = mysql_num_rows($res);
return $rows;
}
function GetFilesByOwner($db, $owner) {
$cnt = $this->GetFilesCountByOwner($db, $owner);
if($cnt == 0) {
return 0; // т.е файлов нет
}
for($i = 1; $i < $cnt + 1; $i++) {
$sql = "SELECT * FROM files WHERE owner='$owner' AND id=$i";
$arr[$i] = $db->QueryAndFetch($sql, null);
}
return $arr;
}
function GetFilesByCategory($db, $category) {
$cnt = $this->GetFilesCountByCategory($db, $category);
if($cnt == 0) {
return 0; // т.е файлов нет
}
for($i = 1; $i < $cnt + 1; $i++) {
$sql = "SELECT * FROM files WHERE category='$category' AND id=$i";
$arr[$i] = $db->QueryAndFetch($sql, null);
}
return $arr;
}
function GetFileInfo($db, $fileid) {
$db->Filter($fileid);
$sql = "SELECT * FROM files WHERE id=$fileid";
return $db->QueryAndFetch($sql, null);
}
function Upload($db, $f, $desc, $name, $gen, $auth) {
$ext = substr($f["name"], strpos($f["name"], "."), strlen($f["name"]));
if($ext == ".png" or $ext == ".jpg" or $ext == ".tga" or $ext == ".bmp") {
$sql = "INSERT INTO `files` (`owner`, `downloads`, `category`, `physical_path`, `name`, `description`) VALUES
(" . $auth->GetUserID($db, $_SESSION["username"]) . ", 0, 'pictures', '$f[name]', '$name', '$desc');";
$db->Query($sql, null);
move_uploaded_file($f["tmp_name"], "uploads/pictures/" . $f["name"]);
$gen->CreateText("Файл успешно загружен!");
$gen->CreateLinkWithIcon("cloud-download", "Перейти к файлу", "files.php?id=" . $this->GetFilesCount($db));
exit;
}
if($ext == ".mp3" or $ext == ".ogg" or $ext == ".mid" or $ext == ".wav") {
$sql = "INSERT INTO `files` (`owner`, `downloads`, `category`, `physical_path`, `name`, `description`) VALUES
(" . $auth->GetUserID($db, $_SESSION["username"]) . ", 0, 'music', '$f[name]', '$name', '$desc');";
$db->Query($sql, null);
move_uploaded_file($f["tmp_name"], "uploads/music/" . $f["name"]);
$gen->CreateText("Файл успешно загружен!");
$gen->CreateLinkWithIcon("cloud-download", "Перейти к файлу", "files.php?id=" . $this->GetFilesCount($db));
exit;
}
if($ext == ".exe" or $ext == ".apk" or $ext == ".zip" or $exp == ".rar") {
$sql = "INSERT INTO `files` (`owner`, `downloads`, `category`, `physical_path`, `name`, `description`) VALUES
(" . $auth->GetUserID($db, $_SESSION["username"]) . ", 0, 'progs', '$f[name]', '$name', '$desc');";
$db->Query($sql, null);
move_uploaded_file($f["tmp_name"], "uploads/progs/" . $f["name"]);
$gen->CreateText("Файл успешно загружен!");
$gen->CreateLinkWithIcon("cloud-download", "Перейти к файлу", "files.php?id=" . $this->GetFilesCount($db));
exit;
}
$sql = "INSERT INTO `files` (`owner`, `downloads`, `category`, `physical_path`, `name`, `description`) VALUES
(" . $auth->GetUserID($db, $_SESSION["username"]) . ", 0, 'other', '$f[name]', '$name', '$desc');";
$db->Query($sql, null);
move_uploaded_file($f["tmp_name"], "uploads/progs/" . $f["name"]);
$gen->CreateText("Файл успешно загружен!");
$gen->CreateLinkWithIcon("cloud-download", "Перейти к файлу", "files.php?id=" . $this->GetFilesCount($db));
exit;
}
function Download($db, $id) {
$db->Filter($id);
$sql = "UPDATE files SET downloads = downloads + 1 WHERE id=$id";
$db->Query($sql, null);
$sql = "SELECT * FROM files WHERE id=$id";
$arr = $db->QueryAndFetch($sql, null);
if($arr["category"] == "pictures") {
$path = "uploads/pictures/" . $arr["physical_path"];
}
if($arr["category"] == "music") {
$path = "uploads/music/" . $arr["physical_path"];
}
if($arr["category"] == "progs") {
$path = "uploads/progs/" . $arr["physical_path"];
}
if($arr["category"] == "other") {
$path = "uploads/other/" . $arr["physical_path"];
}
return $path;
}
}
?>