37 lines
1.4 KiB
PHP
37 lines
1.4 KiB
PHP
<?php
|
|
|
|
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
|
|
|
define('_PROJECT_DIR', getcwd() . '/../'); // Директория проекта
|
|
define('_ROOT_DIR', getcwd() . '/'); // Директория где точка входа php
|
|
define('_SHOP_DIR', getcwd() . '/'); // Директория где точка входа php
|
|
|
|
const _ENGINE_DIR = _PROJECT_DIR . 'engine/';
|
|
const _FILES_DIR_ = _SHOP_DIR . '/files/';
|
|
|
|
include(_ENGINE_DIR. '/core/db.class.php');
|
|
include(_PROJECT_DIR . '/config/db.cfg.php');
|
|
|
|
$transparentPixelGif = 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
|
|
|
|
$id = abs(intval($_GET['id']));
|
|
$core_db->q("SELECT * FROM `_sys_files` WHERE `id` = '".$id."' AND `private` = 0");
|
|
if ($core_db->r()) {
|
|
$data = file_get_contents(_FILES_DIR_ . $core_db->f('filename'));
|
|
if ($data) {
|
|
$val = $id;
|
|
$path = sprintf('%02d/%02d', substr(intval($val), 0, 2), substr(intval($val), 2, 2));
|
|
@mkdir(_ROOT_DIR . '/images/' . $path, 0777, true);
|
|
file_put_contents(_ROOT_DIR . '/images/' . $path .'/'. $id . '.jpg', $data);
|
|
header('Content-type: ' . $core_db->f('ext'));
|
|
die($data);
|
|
} else {
|
|
header('Content-type: image/gif');
|
|
die(base64_decode($transparentPixelGif));
|
|
}
|
|
} else {
|
|
header('Content-type: image/gif');
|
|
die(base64_decode($transparentPixelGif));
|
|
}
|