91 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
		
			3.2 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 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/' . (isset($_GET['w']) || isset($_GET['h']) ? 'thumbs/' : '') . $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');
 | |
|     }
 | |
| }
 |