Просмотр файла siwap.ru/AJAX/news/getNewsFiles.php

Размер файла: 1Kb
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/system/App.php');
	
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' && $_SERVER['REQUEST_METHOD'] == 'POST')
{
	$offset = !empty($_POST['offset']) ? $_POST['offset'] : 0;
	$count = !empty($_POST['count']) ? $_POST['count'] : 10;
	$newsId = !empty($_POST['news_id']) ? $_POST['news_id'] : 0;
	
	$arrNewsFiles = Base::query(
		'SELECT * FROM `news_files` WHERE `news_id` = :news_id ORDER BY `time` DESC LIMIT :offset,:count', [
			'offset/int' => $offset,
			'count/int' => $count,
			'news_id/int' => $newsId
		],
		'arr'
	);
	
	if (!empty($arrNewsFiles) && is_array($arrNewsFiles))
	{
		$json = ['success' => 1, 'files' => $arrNewsFiles];
	}
	else
	{
		$json = ['error' => 1, 'comment' => 'Пока пусто'];
	}
}
else
{
	$json = ['error' => 1, 'comment' => '404 Bad Request'];
}
echo json_encode($json, JSON_UNESCAPED_UNICODE);