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

110 lines
3.9 KiB
PHP
Raw Normal View History

2018-10-16 16:28:42 +00:00
<?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 FROM files WHERE name = ?', [urldecode($title)])->result_array();
2018-10-16 16:28:42 +00:00
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]);
}
2018-12-30 17:39:30 +00:00
$isThumb = isset($_GET['w']) || isset($_GET['h']);
$w = isset($_GET['w']) ? $_GET['w'] : false;
$h = isset($_GET['h']) ? $_GET['h'] : false;
2019-01-04 18:44:00 +00:00
$basePath = str_replace('\\', DIRECTORY_SEPARATOR, $file['path']);
$basePath = str_replace('/', DIRECTORY_SEPARATOR, $basePath);
$imagePath = pathinfo($basePath, PATHINFO_DIRNAME) . '/' .
2018-12-30 17:39:30 +00:00
($isThumb ? 'thumbs/' : '') .
$file['name'] .
($w ? '_w' . $w : '') .
($h ? '_h' . $h : '') .
2019-01-04 18:44:00 +00:00
'.' . pathinfo($basePath, PATHINFO_EXTENSION);
$imagePath = str_replace('/', DIRECTORY_SEPARATOR, $imagePath);
2018-10-16 16:28:42 +00:00
if (!file_exists($imagePath)) {
2018-12-30 17:39:30 +00:00
if(!$isThumb)
exit;
$dir = pathinfo($imagePath, PATHINFO_DIRNAME);
if(!file_exists($dir)) {
mkdir(pathinfo($dir, 0777));
}
2018-10-16 16:28:42 +00:00
$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');
}
}