<?php $headers = GetAllHeaders(); //Заголовки для кроссдоменных запросов header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type, X-Requested-With'); //Подключаемся к БД mysql_connect("localhost", "root", ""); mysql_select_db("test"); mysql_query("SET NAMES 'UTF8'"); $r = json_decode(trim(file_get_contents('php://input')), 1); $url = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1); list($url, $params) = explode('?', $url, 2); $method = $_SERVER['REQUEST_METHOD']; list($script, $section, $id, $action) = explode('/', $url, 4); //Находим объект и тип действия try { switch ($section) { case 'files': //Создаем и инициализируем экземпляр класса для работы с файлами $sql = new Sql('fotorama'); $album = new Album($_REQUEST, array('tableName' => 'fotorama', 'files' => array(array('field' => 'full', 'dir' => 'files_original/', 'fit' => true, 'width' => 1200, 'height' => 1200, 'ext' => 'jpg'), array('field' => 'img', 'dir' => 'files_image/', 'fit' => 'contain', 'width' => 800, 'height' => 800, 'ext' => 'jpg'), array('field' => 'thumb', 'dir' => 'files_thumb/', 'fit' => 'cover', 'width' => 160, 'height' => 160, 'ext' => 'png')), 'maxSize' => '4M', 'maxSpace' => '100M', 'maxNumberOfFiles' => 100, 'allowedType' => array('jpeg', 'jpg', 'png', 'gif', 'bmp', 'psd', 'psp', 'ai', 'eps', 'cdr', 'mp3', 'mp4', 'wav', 'aac', 'aiff', 'midi', 'avi', 'mov', 'mpg', 'flv', 'mpa', 'pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'djvu', 'djv', 'bat', 'cmd', 'dll', 'inf', 'ini', 'ocx', 'sys', 'htm', 'html', 'write', 'none', 'zip', 'rar', 'dmg', 'sitx'))); switch ($method) { case 'GET': $res = isset($id) ? $album->getOne($id) : $album->get(); break; case 'PUT': $res = $album->add(); break; case 'POST':
/* May be invalid if a multisite install lost its config.php; galleryBaseUrl unknown */ header('Location: install/'); return; } if (GalleryUtilities::isEmbedded()) { require_once dirname(__FILE__) . '/init.inc'; } else { /* If this is a request for a public data file, give it to the user immediately */ list($view, $itemId) = GalleryUtilities::getRequestVariables('view', 'itemId'); if ($view == 'core.DownloadItem' && !empty($itemId)) { /* * Our urls are immutable because they have the serial numbers embedded. * So if the browser presents us with an If-Modified-Since then it has * the latest version of the file already. */ if (GalleryUtilities::getServerVar('HTTP_IF_MODIFIED_SINCE') || function_exists('getallheaders') && ($headers = GetAllHeaders()) && (isset($headers['If-Modified-Since']) || isset($headers['If-modified-since']))) { header('HTTP/1.x 304 Not Modified'); return; } /* * Fast download depends on having data.gallery.cache set, so set it now. If for some * reason we fail, we'll reset it in init.inc (but that's ok). */ $gallery->setConfig('data.gallery.cache', $gallery->getConfig('data.gallery.base') . 'cache/'); $path = GalleryDataCache::getCachePath(array('type' => 'fast-download', 'itemId' => $itemId)); /* We don't have a platform yet so we have to use the raw file_exists */ /* Disable fast-download in maintenance mode.. admins still get via core.DownloadItem */ if (file_exists($path) && !$gallery->getConfig('mode.maintenance')) { include $path; if (GalleryFastDownload()) { return;