github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/tinymce/plugins/jbimages/ci/application/controllers/uploader.php (about) 1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 2 3 class Uploader extends CI_Controller { 4 5 /* Constructor */ 6 7 public function __construct() 8 { 9 parent::__construct(); 10 $this->load->helper(array('jbimages','language')); 11 12 // is_allowed is a helper function which is supposed to return False if upload operation is forbidden 13 // [See jbimages/is_alllowed.php] 14 15 if (is_allowed() === FALSE) 16 { 17 exit; 18 } 19 20 // User configured settings 21 $this->config->load('uploader_settings', TRUE); 22 } 23 24 /* Language set */ 25 26 private function _lang_set($lang) 27 { 28 // We accept any language set as lang_id in **_dlg.js 29 // Therefore an error will occur if language file doesn't exist 30 31 $this->config->set_item('language', $lang); 32 $this->lang->load('jbstrings', $lang); 33 } 34 35 /* Default upload routine */ 36 37 public function upload ($lang='english') 38 { 39 // Set language 40 $this->_lang_set($lang); 41 42 // Get configuartion data (we fill up 2 arrays - $config and $conf) 43 44 $conf['img_path'] = $this->config->item('img_path', 'uploader_settings'); 45 $conf['allow_resize'] = $this->config->item('allow_resize', 'uploader_settings'); 46 47 $config['allowed_types'] = $this->config->item('allowed_types', 'uploader_settings'); 48 $config['max_size'] = $this->config->item('max_size', 'uploader_settings'); 49 $config['encrypt_name'] = $this->config->item('encrypt_name', 'uploader_settings'); 50 $config['overwrite'] = $this->config->item('overwrite', 'uploader_settings'); 51 $config['upload_path'] = $this->config->item('upload_path', 'uploader_settings'); 52 53 if (!$conf['allow_resize']) 54 { 55 $config['max_width'] = $this->config->item('max_width', 'uploader_settings'); 56 $config['max_height'] = $this->config->item('max_height', 'uploader_settings'); 57 } 58 else 59 { 60 $conf['max_width'] = $this->config->item('max_width', 'uploader_settings'); 61 $conf['max_height'] = $this->config->item('max_height', 'uploader_settings'); 62 63 if ($conf['max_width'] == 0 and $conf['max_height'] == 0) 64 { 65 $conf['allow_resize'] = FALSE; 66 } 67 } 68 69 // Load uploader 70 $this->load->library('upload', $config); 71 72 if ($this->upload->do_upload()) // Success 73 { 74 // General result data 75 $result = $this->upload->data(); 76 77 // Shall we resize an image? 78 if ($conf['allow_resize'] and $conf['max_width'] > 0 and $conf['max_height'] > 0 and (($result['image_width'] > $conf['max_width']) or ($result['image_height'] > $conf['max_height']))) 79 { 80 // Resizing parameters 81 $resizeParams = array 82 ( 83 'source_image' => $result['full_path'], 84 'new_image' => $result['full_path'], 85 'width' => $conf['max_width'], 86 'height' => $conf['max_height'] 87 ); 88 89 // Load resize library 90 $this->load->library('image_lib', $resizeParams); 91 92 // Do resize 93 $this->image_lib->resize(); 94 } 95 96 // Add our stuff 97 $result['result'] = "file_uploaded"; 98 $result['resultcode'] = 'ok'; 99 $result['file_name'] = $conf['img_path'] . '/' . $result['file_name']; 100 101 // Output to user 102 $this->load->view('ajax_upload_result', $result); 103 } 104 else // Failure 105 { 106 // Compile data for output 107 $result['result'] = $this->upload->display_errors(' ', ' '); 108 $result['resultcode'] = 'failed'; 109 110 // Output to user 111 $this->load->view('ajax_upload_result', $result); 112 } 113 } 114 115 /* Blank Page (default source for iframe) */ 116 117 public function blank($lang='english') 118 { 119 $this->_lang_set($lang); 120 $this->load->view('blank'); 121 } 122 123 public function index($lang='english') 124 { 125 $this->blank($lang); 126 } 127 } 128 129 /* End of file uploader.php */ 130 /* Location: ./application/controllers/uploader.php */