Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param	array
  * @return	void
  */
 public function __construct($props = array())
 {
     if (count($props) > 0) {
         $this->initialize($props);
     }
     $this->mimes =& get_mimes();
     log_message('debug', 'Upload Class Initialized');
 }
Ejemplo n.º 2
0
 public function __construct($namespace = 'xueba', $dir = '/')
 {
     $this->_mimes =& get_mimes();
     $this->_CI =& get_instance();
     $this->_CI->load->config('upload_images');
     $this->config = $this->_CI->config->item('wanpitu');
     $this->namespace = $namespace;
     $this->dir = '/';
 }
Ejemplo n.º 3
0
 public static function getMime($name)
 {
     $mimes =& get_mimes();
     $exp = explode('.', $name);
     $extension = end($exp);
     if (isset($mimes[$extension])) {
         $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
     } else {
         $mime = 'application/octet-stream';
     }
     return $mime;
 }
Ejemplo n.º 4
0
 /**
  * Force Download
  *
  * Generates headers that force a download to happen
  *
  * @param	string	filename
  * @param	mixed	the data to be downloaded
  * @param	bool	whether to try and send the actual file MIME type
  * @return	void
  */
 function force_download($filename = '', $data = '', $set_mime = FALSE)
 {
     if ($filename === '' or $data === '') {
         return FALSE;
     }
     // Set the default MIME type to send
     $mime = 'application/octet-stream';
     $x = explode('.', $filename);
     $extension = end($x);
     if ($set_mime === TRUE) {
         if (count($x) === 1 or $extension === '') {
             /* If we're going to detect the MIME type,
              * we'll need a file extension.
              */
             return FALSE;
         }
         // Load the mime types
         $mimes =& get_mimes();
         // Only change the default MIME if we can find one
         if (isset($mimes[$extension])) {
             $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
         }
     }
     /* It was reported that browsers on Android 2.1 (and possibly older as well)
      * need to have the filename extension upper-cased in order to be able to
      * download it.
      *
      * Reference: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
      */
     if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\\s(1|2\\.[01])/', $_SERVER['HTTP_USER_AGENT'])) {
         $x[count($x) - 1] = strtoupper($extension);
         $filename = implode('.', $x);
     }
     // Clean output buffer
     if (ob_get_level() !== 0) {
         ob_clean();
     }
     // Generate the server headers
     header('Content-Type: ' . $mime);
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Expires: 0');
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . strlen($data));
     // Internet Explorer-specific headers
     if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     } else {
         header('Pragma: no-cache');
     }
     exit($data);
 }
Ejemplo n.º 5
0
 public function common_functions()
 {
     echo is_php('5.3');
     echo is_really_writable('file.php');
     echo config_item('key');
     echo set_status_header('200', 'text');
     echo remove_invisible_characters('Java\\0script');
     echo html_escape(array());
     echo get_mimes();
     echo is_https();
     echo is_cli();
     echo function_usable('eval');
 }
Ejemplo n.º 6
0
 public static function download($uuid, $filename, $set_mime = TRUE)
 {
     $CI =& get_instance();
     $config = $CI->config->item('utils');
     list($secureId, $id, $path) = self::getData($uuid);
     $filepath = $config['file_dir'] . $path . '/' . self::getFileName($id, $path) . '.backup';
     $filesize = filesize($filepath);
     $mime = 'application/octet-stream';
     $x = explode('.', $filename);
     $extension = end($x);
     if ($set_mime === TRUE) {
         if (count($x) === 1 or $extension === '') {
             return;
         }
         $mimes =& get_mimes();
         if (isset($mimes[$extension])) {
             $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
         }
     }
     if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\\s(1|2\\.[01])/', $_SERVER['HTTP_USER_AGENT'])) {
         $x[count($x) - 1] = strtoupper($extension);
         $filename = implode('.', $x);
     }
     if (($fp = @fopen($filepath, 'rb')) === FALSE) {
         return self::NOT_FOUND;
     }
     if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) {
         @ob_clean();
     }
     header('Content-Type: ' . $mime);
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Expires: 0');
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . $filesize);
     if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
         header('Cache-Control: no-cache, no-store, must-revalidate');
     }
     header('Pragma: no-cache');
     while (!feof($fp) && ($data = fread($fp, 1048576)) !== FALSE) {
         echo $data;
     }
     fclose($fp);
     exit;
 }
 public function GetResults()
 {
     $mimes =& get_mimes();
     $rootFolderID = NULL;
     $items = NULL;
     $folders = array();
     if (get_inventory($this->User['UserID'], $rootFolderID, $items)) {
         foreach ($items as $item) {
             $type = isset($mimes[$item['ContentType']]) ? $mimes[$item['ContentType']] : -1;
             $folders[] = array('folder_id' => $item['ID'], 'name' => $item['Name'], 'parent_id' => $item['ParentID'], 'version' => (int) $item['Version'], 'type_default' => (int) $type);
         }
     } else {
         log_message('error', 'Failed to fetch inventory skeleton for ' . $this->User['UserID']);
         // Allowing the viewer to login with an empty inventory skeleton does bad things. Better
         // to just bail out
         exit;
     }
     log_message('debug', 'Returning ' . count($folders) . ' inventory folders in the skeleton');
     return $folders;
 }
 public function GetResults()
 {
     $mimes =& get_mimes();
     // Get the library owner ID
     $userID = NULL;
     if (!get_library_owner($userID)) {
         log_message('warn', '[inventory_skel_lib] failed to get library owner');
         return array();
     } else {
         // Get the root folder ID
         $rootFolderID = $userID;
         if (!get_library_root_folder($userID, $rootFolderID)) {
             log_message('warn', '[inventory_skel_lib] failed to get library root');
             return array();
         }
         // Get the items from the inventory folder
         $items = NULL;
         if (!get_inventory_items($userID, $rootFolderID, 0, $items)) {
             log_message('warn', '[inventory_skel_lib] failed to get library contents');
             return array();
         }
         // Build the output folder structure
         $folders = array();
         foreach ($items as $item) {
             $type = isset($mimes[$item['ContentType']]) ? $mimes[$item['ContentType']] : -1;
             $parentid = $item['ParentID'];
             $folderid = $item['ID'];
             $foldername = $item['Name'];
             if ($folderid == $rootFolderID) {
                 $parentid = '00000000-0000-0000-0000-000000000000';
             }
             $folders[] = array('folder_id' => $folderid, 'name' => $foldername, 'parent_id' => $parentid, 'version' => (int) $item['Version'], 'type_default' => (int) $type);
         }
         log_message('debug', sprintf('[inventory_skel_lib] %d folders from %s owned by %s', count($folders), $rootFolderID, $userID));
         return $folders;
     }
 }
Ejemplo n.º 9
0
 function qiniu_upload($name, $type = 'gif|jpg|png')
 {
     $tmp_file = $_FILES[$name];
     if (!isset($tmp_file['name']) || isset($tmp_file['name']) && empty($tmp_file['name'])) {
         return '';
     }
     $minis =& get_mimes();
     $type = explode('|', $type);
     $flag = FALSE;
     foreach ($type as $item) {
         if (isset($minis[$item])) {
             if (is_array($minis[$item]) && in_array($tmp_file['type'], $minis[$item]) || is_string($minis[$item]) && $tmp_file['type'] == $minis[$item]) {
                 $flag = TRUE;
             }
         }
     }
     if (!$flag) {
         return FALSE;
     }
     $CI =& get_instance();
     $CI->load->model('qiniu_model', 'qiniu');
     if (isset($_SESSION['qiniu_token'])) {
         $token = $_SESSION['qiniu_token'];
     } else {
         $token = $CI->qiniu->get_token();
         $CI->session->set_tempdata('qiniu_token', $token, 3000);
     }
     $file_name = 'ci_set/' . date('Y/m/dH/i/s', time()) . md5(substr($tmp_file['name'], 0, strrpos($tmp_file['name'], '.')) . time()) . substr($tmp_file['name'], strrpos($tmp_file['name'], '.'));
     $ret = $CI->qiniu->upload_file($token, $tmp_file['tmp_name'], $file_name);
     if (isset($ret['key'])) {
         return $ret['key'];
     }
     return FALSE;
 }
Ejemplo n.º 10
0
 /**
  * Class constructor.
  *
  * Determines whether zLib output compression will be used.
  *
  * @return void
  */
 public function __construct()
 {
     $this->_zlib_oc = (bool) ini_get('zlib.output_compression');
     $this->_compress_output = $this->_zlib_oc === false && config_item('compress_output') === true && extension_loaded('zlib');
     // Get mime types for later
     $this->mimes =& get_mimes();
     log_message('info', 'Output Class Initialized');
 }
Ejemplo n.º 11
0
 public function view($file, $type)
 {
     global $ci, $page;
     $file .= '.' . $type;
     $type = strtolower($type);
     $image = $compress = $deliver = $download = $stream = false;
     if (preg_match('/^(jpe?g|gif|png|ico)$/', $type)) {
         $image = $type;
     } elseif (preg_match('/^(js|css|pdf|ttf|otf|svg)$/', $type)) {
         $compress = $type;
     } elseif (preg_match('/^(eot|woff2?|swf)$/', $type)) {
         $deliver = $type;
     } elseif (preg_match('/^(tar|t?gz|zip|csv|xls?x?|word|docx?|ppt|psd)$/', $type)) {
         $download = $type;
     } elseif (preg_match('/^(ogg|wav|mp3|mp4|mpeg?|mpg|mov|qt)$/', $type)) {
         $stream = $type;
     } else {
         exit(header('HTTP/1.1 503 Not Implemented'));
     }
     if ($this->cached($file)) {
         list($files, $updated) = $this->file_paths($file);
         if (empty($files)) {
             exit(header('HTTP/1.1 404 Not Found'));
         }
         $cache = array_shift($files);
         // Only one file at a time is allowed now
         $updated = array_shift($updated);
         if (preg_match('/^.{5}\\/((~)?([0-9]{1,3})[x]{1}([0-9]{1,3})(:[0-9]{1,3})?)[\\/\\.]{1}/', $file, $matches)) {
             $thumb = BASE_URI . 'thumbs/' . md5($cache) . '/' . rawurlencode($matches[1]) . '.' . $type;
             if (!is_file($thumb) || filemtime($thumb) < $updated) {
                 // create the image thumb
                 require_once BASE . 'Page.php';
                 $page = new Page();
                 $thumbnail = $page->plugin('Image', 'uri', $cache);
                 if ($matches[2] == '~') {
                     $thumbnail->constrain($matches[3], $matches[4]);
                 } else {
                     $thumbnail->resize($matches[3], $matches[4], 'enforce');
                 }
                 $thumbnail->save($thumb, isset($matches[5]) ? min(substr($matches[5], 1), 100) : 80);
             }
             $cache = $thumb;
             $updated = filemtime($thumb);
         }
         if (!$download && !$stream) {
             $this->never_expires($updated);
         }
         if ($compress == 'pdf' || $download || $stream) {
             $ci->load->driver('session');
             $resource = str_replace(array(BASE_URI, BASE), '', $cache);
             $resource .= '#' . substr(strstr($ci->uri->uri_string(), '/'), 1);
             $ci->log_analytics('hits', $resource);
         }
     } elseif (strpos($file, 'CDN') !== false && is_file(BASE . $file)) {
         $cache = BASE . $file;
         $this->never_expires(filemtime($cache));
     } elseif ($file == 'favicon.ico') {
         $cache = dirname(__DIR__) . DIRECTORY_SEPARATOR . $file;
         $this->never_expires(filemtime($cache));
     } else {
         exit(header('HTTP/1.1 404 Not Found'));
     }
     $mimes =& get_mimes();
     header('Content-Type: ' . (is_array($mimes[$type]) ? array_shift($mimes[$type]) : $mimes[$type]));
     if ($compress) {
         $supported = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '';
         $gzip = strstr($supported, 'gzip');
         $deflate = strstr($supported, 'deflate');
         $encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');
         if (isset($_SERVER['HTTP_USER_AGENT']) && !strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && preg_match('/^Mozilla\\/4\\.0 \\(compatible; MSIE ([0-9]\\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
             $version = floatval($matches[1]);
             if ($version < 6) {
                 $encoding = 'none';
             }
             if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) {
                 $encoding = 'none';
             }
         }
         $cache = $type == 'css' ? $this->css_get_contents($cache, $file) : file_get_contents($cache);
         if ($encoding != 'none') {
             $cache = gzencode($cache, 9, $encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE);
             header('Vary: Accept-Encoding');
             header('Content-Encoding: ' . $encoding);
         }
         header('Content-Length: ' . strlen($cache));
         exit($cache);
     }
     if (!($fp = fopen($cache, 'rb'))) {
         header('HTTP/1.1 500 Internal Server Error');
         exit;
     }
     $size = filesize($cache);
     if ($download || $stream) {
         ini_set('zlib.output_compression', 'Off');
         $length = $size;
         $start = 0;
         $end = $size - 1;
         if ($range = $ci->input->server('HTTP_RANGE')) {
             // serve a partial file
             if (preg_match('%bytes=(\\d+)-(\\d+)?%i', $range, $match)) {
                 $match = array_map('intval', $match);
                 if (!isset($match[2])) {
                     $match[2] = $end;
                 }
                 $length = $match[2] - $match[1] + 1;
             }
             if ($length <= $size) {
                 fseek($fp, $match[1]);
                 header('HTTP/1.1 206 Partial Content');
                 header("Content-Range: bytes {$match[1]}-{$match[2]}/{$size}");
             } else {
                 header('HTTP/1.1 416 Requested Range Not Satisfiable');
                 header("Content-Range: bytes {$start}-{$end}/{$size}");
                 exit;
             }
         }
         header('Accept-Ranges: bytes');
         header('Connection: Keep-Alive"');
         header('X-Pad: avoid browser bug');
         header('Pragma: public');
         // Fix IE6 Content-Disposition
         header('Expires: -1');
         // Prevent caching
         header('Cache-Control: public, must-revalidate, post-check=0, pre-check=0');
         header('Etag: "' . filemtime($cache) . '-' . md5($cache) . '"');
         // Enable resumable download in IE9.
         if ($download) {
             header('Content-Disposition: attachment; filename="' . basename($file) . '"');
         } elseif ($stream) {
             header('Content-Disposition: inline;');
             header('Content-Transfer-Encoding: binary');
         }
         $size = $length;
     }
     header('Content-Length: ' . $size);
     ob_end_clean();
     while ($size) {
         set_time_limit(0);
         $read = $size > 8192 ? 8192 : $size;
         $size -= $read;
         echo fread($fp, $read);
         flush();
     }
     fclose($fp);
     exit;
 }
Ejemplo n.º 12
0
 /**
  * Constructor
  *
  * @param  array $props
  * @return  void
  */
 public function __construct($config = array())
 {
     empty($config) or $this->initialize($config, FALSE);
     $this->_mimes =& get_mimes();
     $this->_CI =& get_instance();
     log_message('info', 'Upload Class Initialized');
 }
Ejemplo n.º 13
0
 /**
  * Mime Types
  *
  * @param	string
  * @return	string
  */
 protected function _mime_types($ext = '')
 {
     $ext = strtolower($ext);
     $mimes =& get_mimes();
     if (isset($mimes[$ext])) {
         return is_array($mimes[$ext]) ? current($mimes[$ext]) : $mimes[$ext];
     }
     return 'application/x-unknown-content-type';
 }
Ejemplo n.º 14
0
 /**
  * Force Download
  * 推动强迫下载
  * Generates headers that force a download to happen
  * 生成头文件强制下载发生
  * @param	string	filename  文件名称
  * @param	mixed	the data to be downloaded  下载的数据
  * @param	bool	whether to try and send the actual file MIME type 是否要试着发送实际的文件的MIME类型
  * @return	void
  */
 function force_download($filename = '', $data = '', $set_mime = FALSE)
 {
     if ($filename === '' or $data === '') {
         return;
     } elseif ($data === NULL) {
         if (!@is_file($filename) or ($filesize = @filesize($filename)) === FALSE) {
             return;
         }
         $filepath = $filename;
         $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename));
         $filename = end($filename);
     } else {
         $filesize = strlen($data);
     }
     // Set the default MIME type to send 设置默认发送MIME类型
     $mime = 'application/octet-stream';
     $x = explode('.', $filename);
     $extension = end($x);
     if ($set_mime === TRUE) {
         if (count($x) === 1 or $extension === '') {
             /* If we're going to detect the MIME type, 如果我们要检测的MIME类型,
              * we'll need a file extension.  我们需要一个文件扩展名。
              */
             return;
         }
         // Load the mime types  加载mime类型
         $mimes =& get_mimes();
         // Only change the default MIME if we can find one  只改变默认的MIME如果我们能找到一个
         if (isset($mimes[$extension])) {
             $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
         }
     }
     /* It was reported that browsers on Android 2.1 (and possibly older as well)
      * need to have the filename extension upper-cased in order to be able to
      * download it.
      * 据报道,浏览器在Android 2.1(也可能是旧的)需要文件扩展名大写为了能够下载它。
      * Reference参考: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
      */
     if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\\s(1|2\\.[01])/', $_SERVER['HTTP_USER_AGENT'])) {
         $x[count($x) - 1] = strtoupper($extension);
         $filename = implode('.', $x);
     }
     if ($data === NULL && ($fp = @fopen($filepath, 'rb')) === FALSE) {
         return;
     }
     // Clean output buffer 干净的输出缓冲区
     if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) {
         @ob_clean();
     }
     // Generate the server headers 生成服务器头信息
     header('Content-Type: ' . $mime);
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Expires: 0');
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . $filesize);
     header('Cache-Control: private, no-transform, no-store, must-revalidate');
     // If we have raw data - just dump it 如果我们有原始数据,将扔弃它
     if ($data !== NULL) {
         exit($data);
     }
     // Flush 1MB chunks of data  冲洗1MB的数据块
     while (!feof($fp) && ($data = fread($fp, 1048576)) !== FALSE) {
         echo $data;
     }
     fclose($fp);
     exit;
 }
Ejemplo n.º 15
0
 /**
  * Class constructor
  *
  * Determines whether zLib output compression will be used.
  *
  * @return	void
  */
 public function __construct()
 {
     // global $BM, $CFG;
     $CFG =& load_class('Config', 'core');
     $BM =& load_class('Benchmark', 'core');
     $this->_zlib_oc = (bool) ini_get('zlib.output_compression');
     $this->_compress_output = $this->_zlib_oc === FALSE && config_item('compress_output') === TRUE && extension_loaded('zlib');
     // Get mime types for later
     $this->mimes =& get_mimes();
     log_message('info', 'Output Class Initialized');
 }
Ejemplo n.º 16
0
 /**
  * Force Download
  *
  * Generates headers that force a download to happen
  *
  * @param	string	filename
  * @param	mixed	the data to be downloaded
  * @param	bool	whether to try and send the actual file MIME type
  * @return	void
  */
 function force_download($filename = '', $data = '', $set_mime = FALSE)
 {
     if ($filename === '' or $data === '') {
         return;
     } elseif ($data === NULL) {
         if (@is_file($filename) && ($filesize = @filesize($filename)) !== FALSE) {
             $filepath = $filename;
             $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename));
             $filename = end($filename);
         } else {
             return;
         }
     } else {
         $filesize = strlen($data);
     }
     // Set the default MIME type to send
     $mime = 'webapps/octet-stream';
     $x = explode('.', $filename);
     $extension = end($x);
     if ($set_mime === TRUE) {
         if (count($x) === 1 or $extension === '') {
             /* If we're going to detect the MIME type,
              * we'll need a file extension.
              */
             return;
         }
         // Load the mime types
         $mimes =& get_mimes();
         // Only change the default MIME if we can find one
         if (isset($mimes[$extension])) {
             $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
         }
     }
     /* It was reported that browsers on Android 2.1 (and possibly older as well)
      * need to have the filename extension upper-cased in order to be able to
      * download it.
      *
      * Reference: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
      */
     if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\\s(1|2\\.[01])/', $_SERVER['HTTP_USER_AGENT'])) {
         $x[count($x) - 1] = strtoupper($extension);
         $filename = implode('.', $x);
     }
     if ($data === NULL && ($fp = @fopen($filepath, 'rb')) === FALSE) {
         return;
     }
     // Clean output buffer
     if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) {
         @ob_clean();
     }
     // Generate the server headers
     header('Content-Type: ' . $mime);
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Expires: 0');
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . $filesize);
     // Internet Explorer-specific headers
     if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
         header('Cache-Control: no-cache, no-store, must-revalidate');
     }
     header('Pragma: no-cache');
     // If we have raw data - just dump it
     if ($data !== NULL) {
         exit($data);
     }
     // Flush 1MB chunks of data
     while (!feof($fp) && ($data = fread($fp, 1048576)) !== FALSE) {
         echo $data;
     }
     fclose($fp);
     exit;
 }
Ejemplo n.º 17
0
 /**
  * Class constructor
  *
  * Determines whether zLib output compression will be used.
  *
  * @return	void
  */
 public function __construct()
 {
     $this->_zlib_oc = (bool) @ini_get('zlib.output_compression');
     // Get mime types for later
     $this->mimes =& get_mimes();
     log_message('debug', 'Output Class Initialized');
 }
Ejemplo n.º 18
0
 /**
  * Constructor
  *
  * @param	array	$props
  * @return	void
  */
 public function __construct($config = array())
 {
     empty($config) or $this->initialize($config, FALSE);
     $this->_mimes =& get_mimes();
     $this->_CI =& get_instance();
     log_message('debug', 'Upload Class Initialized');
     $this->_types = array('upload_userfile_not_set' => lang('Unable to find a post variable called userfile.'), 'upload_file_exceeds_limit' => lang('The uploaded file exceeds the maximum allowed size in your PHP configuration file.'), 'upload_file_exceeds_form_limit' => lang('The uploaded file exceeds the maximum size allowed by the submission form.'), 'upload_file_partial' => lang('The file was only partially uploaded.'), 'upload_no_temp_directory' => lang('The temporary folder is missing.'), 'upload_unable_to_write_file' => lang('The file could not be written to disk.'), 'upload_stopped_by_extension' => lang('The file upload was stopped by extension.'), 'upload_no_file_selected' => lang('You did not select a file to upload.'), 'upload_invalid_filetype' => lang('The filetype you are attempting to upload is not allowed.'), 'upload_invalid_filesize' => lang('The file you are attempting to upload is larger than the permitted size.'), 'upload_invalid_dimensions' => lang('The image you are attempting to upload doesn\'t fit into the allowed dimensions.'), 'upload_destination_error' => lang('A problem was encountered while attempting to move the uploaded file to the final destination.'), 'upload_no_filepath' => lang('The upload path does not appear to be valid.'), 'upload_no_file_types' => lang('You have not specified any allowed file types.'), 'upload_bad_filename' => lang('The file name you submitted already exists on the server.'), 'upload_not_writable' => lang('The upload destination folder does not appear to be writable.'));
 }
Ejemplo n.º 19
0
 /**
  * Get Mime by Extension
  *
  * Translates a file extension into a mime type based on config/mimes.php.
  * Returns FALSE if it can't determine the type, or open the mime config file
  *
  * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
  * It should NOT be trusted, and should certainly NOT be used for security
  *
  * @param	string	path to file
  * @return	mixed
  */
 function get_mime_by_extension($file)
 {
     $extension = strtolower(substr(strrchr($file, '.'), 1));
     static $mimes;
     if (!is_array($mimes)) {
         $mimes =& get_mimes();
         if (empty($mimes)) {
             return FALSE;
         }
     }
     if (isset($mimes[$extension])) {
         return is_array($mimes[$extension]) ? current($mimes[$extension]) : $mimes[$extension];
     }
     return FALSE;
 }
Ejemplo n.º 20
0
Archivo: core.php Proyecto: ejz/core
function check_mime($file)
{
    if (!is_file($file)) {
        return;
    }
    if (!function_exists('finfo_open')) {
        _log("NOT DEFINED | finfo_open", E_USER_ERROR);
    }
    if (!defined('FILEINFO_MIME_TYPE')) {
        _log("NOT DEFINED | FILEINFO_MIME_TYPE", E_USER_ERROR);
    }
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $type = finfo_file($finfo, $file);
    finfo_close($finfo);
    $nargs = func_num_args();
    if ($nargs == 1) {
        return $type;
    }
    $mimes = get_mimes(func_get_arg(1));
    if (!isset($mimes[$type])) {
        return false;
    }
    if ($nargs == 2) {
        return true;
    }
    $check = func_get_arg(2);
    if (!$check) {
        return true;
    }
    return in_array(file_get_ext($file), $mimes[$type]);
}
Ejemplo n.º 21
0
 /**
  * Class constructor
  *
  * Determines whether zLib output compression will be used.
  *
  * @return	void
  */
 public function __construct()
 {
     $this->_zlib_oc = (bool) ini_get('zlib.output_compression');
     $this->_compress_output = $this->_zlib_oc === FALSE && config_item('compress_output') === TRUE && extension_loaded('zlib');
     isset(self::$func_override) or self::$func_override = extension_loaded('mbstring') && ini_get('mbstring.func_override');
     // Get mime types for later
     $this->mimes =& get_mimes();
     log_message('info', 'Output Class Initialized');
 }
Ejemplo n.º 22
0
 function import()
 {
     $header['title'] = IMPORT_STUDENT;
     $data['error'] = '';
     if ($this->input->post()) {
         $file = $_FILES['uploadfile'];
         $error = null;
         if ($file['error']) {
             $error = 'File không hợp lệ';
         }
         $mimes = get_mimes();
         if (!$error && !in_array($file['type'], $mimes['xls'])) {
             $error = 'File phải là xls';
         }
         // need to check filesize more
         if (!$error) {
             $filename = BACKEND_V2_TMP_PATH_ROOT . basename($file['name']);
             if (move_uploaded_file($file['tmp_name'], $filename)) {
                 $class_id = intval($this->input->post('class_id'));
                 $academic_id = intval($this->input->post('academic_id'));
                 if ($class_id && $academic_id) {
                     $this->_saveFileData($class_id, $academic_id, $file['name']);
                     redirect(BACKEND_V2_TMPL_PATH . 'students/lists');
                 }
             } else {
                 $data['error'] = "Không thể upload file";
             }
         } else {
             $data['error'] = $error;
         }
     }
     $data['title'] = $header['title'];
     $data['classes'] = $this->class_model->getAll();
     $data['academics'] = $this->academic_model->getAll();
     $content = $this->load->view(BACKEND_V2_TMPL_PATH . 'students/import', $data, TRUE);
     $this->loadTemnplateBackend($header, $content);
 }