View file api/file.php

File size: 2.67Kb
<?php
require_once '../system/function.php';

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=utf8');
header('Access-Control-Allow-Methods: GET');

$data = null;

if (!empty($_GET['id'])) {
	$id = abs(intval($_GET['id']));

	$set = $db->query('SELECT * FROM `set`')->fetch_assoc();

	$check = $db->query('SELECT * FROM `file` WHERE `id` = '.$id)->fetch_assoc();
	if (!isset($_SESSION['file'.$id]) and $check != 0 and $guest['ua'] != 'NULLED_USER_AGENT') {
		$db->query('UPDATE `file` SET `views` = `views` +1 WHERE `id` = '.$id);
	}
	$_SESSION['file'.$id] = true;

	$get_file = 'SELECT * FROM `file` WHERE `id` = '.$id;
	$q = $db->query($get_file) or die();
	while ($a = $q->fetch_assoc()) {
		if ($a['del'] != 0) {
			$avto = $a['del'] * 86400;
		} else {
			$avto = $set['del'] * 86400;
		}

		$a['time_up'] = date($a['time']-$avto);
		if ($a['pass'] == 0) {
			$data = array(
				'data' => [
					'id' => (int)$a['id'],
					'url' => 'https://'.$_SERVER['HTTP_HOST'].'/file'.$a['id'],
					'name' => $a['name'],
					'opis' => $a['opis'],
					'file' => 'https://'.$_SERVER['HTTP_HOST'].'/files/'.$a['file'],
					'file_size' => sizer(filesize(H.'/files/'.$a['file'])),
					'load' => (int)$a['up'],
					'like' => (int)$a['like'],
					'views' => (int)$a['views'],
					'comments' => (int)$db->query('SELECT COUNT(*) FROM `komm` WHERE `file` = '.$a['id'])->fetch_row()[0],
					'format' => $a['format'],
					'time' => (int)$a['time_up'],
					'time_del' => (int)$a['time'],
					'author' => $a['avtor'],
					'password' => false,
			        'access' => $a['access']
				]
			);
		} else {
			$data = array(
				'data' => [
					'id' => (int)$a['id'],
					'url' => 'https://'.$_SERVER['HTTP_HOST'].'/file'.$a['id'],
					'name' => $a['name'],
					'opis' => $a['opis'],
					'file' => 'https://'.$_SERVER['HTTP_HOST'].'/file'.$a['id'],
					'file_size' => sizer(filesize(H.'/files/'.$a['file'])),
					'load' => (int)$a['up'],
					'like' => (int)$a['like'],
					'views' => (int)$a['views'],
					'comments' => (int)$db->query('SELECT COUNT(*) FROM `komm` WHERE `file` = '.$a['id'])->fetch_row()[0],
					'format' => 'locked',
					'time' => (int)$a['time_up'],
					'time_del' => (int)$a['time'],
					'author' => $a['avtor'],
					'password' => true,
			        'access' => $a['access']
				]
			);
		}
	}
	if ($check == 0) {
		$data = array(
			'data' => [
				'error' => "Bad Request",
				'message' => "File Not Found"
			],
			'success' => false,
			'status' => 400
		);
	}
} else {
	$data = array(
		'data' => [
			'error' => "Bad Request",
			'message' => "Empty Request"
		],
		'success' => false,
		'status' => 400
	);
}

echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit;