Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/controllers/File.php

96 lines
3.4 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class File extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function open($title = null, $download = false)
{
if ($title == null) {
redirect(base_url());
} else {
$file = $this->db->query('SELECT name, type, path, isUserData FROM files WHERE name = ?', [urldecode($title)])->result_array();
if (!empty($file)) {
$file = $file[0];
// TODO: FIX!
// header("Content-length: " . $file['size']);
header("Content-type: " . $file['type']);
if ($download) {
header("Content-Disposition: attachment; filename=" . $file['name'] . '.' . explode('/', $file['type'])[1]);
}
$imagePath = 'files' . DIRECTORY_SEPARATOR .
($file['isUserData'] ? 'userContent' . DIRECTORY_SEPARATOR : '') .
(isset($_GET['w']) || isset($_GET['h']) ? 'thumbs' . DIRECTORY_SEPARATOR : '') .
$file['name'] . (isset($_GET['w']) ? '_w' . $_GET['w'] : '') .
(isset($_GET['h']) ? '_h' . $_GET['h'] : '') . '.' .
explode('.', $file['path'])[1];
if (!file_exists($imagePath)) {
$config['image_library'] = 'gd2';
$config['source_image'] = $file['path'];
if (isset($_GET['w'])) {
$config['width'] = $_GET['w'];
}
if (isset($_GET['h'])) {
$config['height'] = $_GET['h'];
}
$config['maintain_ratio'] = TRUE;
$config['new_image'] = $imagePath;
$this->load->library('image_lib', $config);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
}
readfile(base_url($imagePath));
exit;
} else {
redirect(base_url());
}
}
}
public function thumbnail($videoID = null)
{
if ($videoID !== null && strlen($videoID) == 11) {
$thumbnail_url = "http://img.youtube.com/vi/" . $videoID . "/maxresdefault.jpg";
header("Content-Type: image/jpeg");
readfile($thumbnail_url);
} else {
redirect(base_url());
}
}
public function csgo($category = null, $item = null)
{
if ($category == null || $item == null) {
redirect(base_url());
} else {
if ($category == 'weapon') {
header("Content-Type: image/png");
readfile('http://csgo-stats.com/img/weapons/3d/' . $item . '.png');
} elseif ($category == 'map') {
header("Content-Type: image/jpeg");
readfile('http://csgo-stats.com/img/maps/' . $item . '.jpg');
} elseif ($category = 'mapicon') {
header("Content-Type: image/png");
readfile('http://csgo-stats.com/img/maps/icons/' . $item . '.png');
}
}
}
public function weapon()
{
header("Content-Type: image/jpeg");
readfile('http://csgo-stats.com/img/weapons/bg.jpg');
}
}