add check img type by data

This commit is contained in:
october 2017-04-19 15:32:46 +08:00
parent 113a0f1d62
commit 01de45e729

View File

@ -1,140 +1,147 @@
<?php <?php
/*文件扩展名说明 /*文件扩展名说明
*7173 gif *255216 jpg *13780 png *6677 bmp *239187 txt,aspx,asp,sql *208207 xls.doc.ppt *6063 xml *6033 htm,html *4742 js *7173 gif *255216 jpg *13780 png *6677 bmp *239187 txt,aspx,asp,sql *208207 xls.doc.ppt *6063 xml *6033 htm,html *4742 js
*8075 xlsx,zip,pptx,mmap,zip *8297 rar *01 accdb,mdb *7790 exe,dll *5666 psd *255254 rdp *10056 bt种子 *64101 bat *8075 xlsx,zip,pptx,mmap,zip *8297 rar *01 accdb,mdb *7790 exe,dll *5666 psd *255254 rdp *10056 bt种子 *64101 bat
*/ */
function getFileType( $file ){ function getFileTypeByRaw( $data ){
$fp = fopen($file, "rb"); $bin = $data[0].$data[1];
$bin = fread($fp, 2); //只读2字节 return getFileTypeBybin( $bin );
fclose($fp); }
$str_info = @unpack("C2chars", $bin); function getFileType( $file ){
$type_code = intval($str_info['chars1'].$str_info['chars2']); $fp = fopen($file, "rb");
$file_type = ''; $bin = fread($fp, 2); //只读2字节
switch ($type_code) { fclose($fp);
case 239187: return getFileTypeBybin( $bin );
$file_type = 'txt'; }
break; function getFileTypeBybin( $bin ){
case 7784: $str_info = @unpack("C2chars", $bin);
$file_type = 'midi'; $type_code = intval($str_info['chars1'].$str_info['chars2']);
break; $file_type = '';
case 8075: switch ($type_code) {
$file_type = 'zip'; case 239187:
break; $file_type = 'txt';
case 8297: break;
$file_type = 'rar'; case 7784:
break; $file_type = 'midi';
case 255216: break;
$file_type = 'jpg'; case 8075:
break; $file_type = 'zip';
case 7173: break;
$file_type = 'gif'; case 8297:
break; $file_type = 'rar';
case 6677: break;
$file_type = 'bmp'; case 255216:
break; $file_type = 'jpg';
case 13780: break;
$file_type = 'png'; case 7173:
break; $file_type = 'gif';
default: break;
$file_type = 'unknown'; case 6677:
break; $file_type = 'bmp';
} break;
return $file_type; case 13780:
} $file_type = 'png';
function isAjax(){ break;
if( isset( $GLOBALS['__isAjax'] ) ){ default:
return $GLOBALS['__isAjax']; $file_type = 'unknown';
} break;
$headers = apache_request_headers(); }
$GLOBALS['__isAjax'] = (isset( $headers['X-Requested-With'] ) && ( $headers['X-Requested-With'] == 'XMLHttpRequest' )) || (isset( $headers['x-requested-with'] ) && ($headers['x-requested-with'] == 'XMLHttpRequest' )); return $file_type;
return $GLOBALS['__isAjax']; }
} function isAjax(){
function c( $name ){ if( isset( $GLOBALS['__isAjax'] ) ){
if( !isset( $GLOBALS['__config'] ) ){ return $GLOBALS['__isAjax'];
$__config = NULL; }
include( ENGINE.'config/core.config.php' ); $headers = apache_request_headers();
include( ROOT.'config/app.config.php' ); $GLOBALS['__isAjax'] = (isset( $headers['X-Requested-With'] ) && ( $headers['X-Requested-With'] == 'XMLHttpRequest' )) || (isset( $headers['x-requested-with'] ) && ($headers['x-requested-with'] == 'XMLHttpRequest' ));
$GLOBALS['__config'] = $__config; return $GLOBALS['__isAjax'];
} }
if( isset( $GLOBALS['__config'][$name] ) ){ function c( $name ){
return $GLOBALS['__config'][$name]; if( !isset( $GLOBALS['__config'] ) ){
} $__config = NULL;
else{ include( ENGINE.'config/core.config.php' );
return false; include( ROOT.'config/app.config.php' );
} $GLOBALS['__config'] = $__config;
} }
function db(){ if( isset( $GLOBALS['__config'][$name] ) ){
if( !$GLOBALS['__db'] ){ return $GLOBALS['__config'][$name];
$GLOBALS['__db'] = new Db(); }
} else{
return $GLOBALS['__db']; return false;
} }
function get_ip() { }
if (isSet($_SERVER)) { function db(){
if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) { if( !$GLOBALS['__db'] ){
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"]; $GLOBALS['__db'] = new Db();
} elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) { }
$realip = $_SERVER["HTTP_CLIENT_IP"]; return $GLOBALS['__db'];
} else { }
$realip = $_SERVER["REMOTE_ADDR"]; function get_ip() {
} if (isSet($_SERVER)) {
} else { if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) {
if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
$realip = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) {
} elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $realip = $_SERVER["HTTP_CLIENT_IP"];
$realip = getenv( 'HTTP_CLIENT_IP' ); } else {
} else { $realip = $_SERVER["REMOTE_ADDR"];
$realip = getenv( 'REMOTE_ADDR' ); }
} } else {
} if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
return current( explode(',' , $realip ) ); $realip = getenv( 'HTTP_X_FORWARDED_FOR' );
} } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
function v( $str ){ $realip = getenv( 'HTTP_CLIENT_IP' );
return getDataFromArray( $str , $_REQUEST ); } else {
} $realip = getenv( 'REMOTE_ADDR' );
function p( $str ){ }
return getDataFromArray( $str , $_POST ); }
} return current( explode(',' , $realip ) );
function getDataFromArray( $array , $data ){ }
if( is_array( $array ) ){ function v( $str ){
$return = array(); return getDataFromArray( $str , $_REQUEST );
foreach( $array as $v ){ }
if( isset( $data[$v] ) && $data[$v] !== '' ){ function p( $str ){
$return[trim($v)] = $data[$v]; return getDataFromArray( $str , $_POST );
} }
} function getDataFromArray( $array , $data ){
return $return; if( is_array( $array ) ){
} $return = array();
return isset( $data[$array] )?$data[$array]:false; foreach( $array as $v ){
} if( isset( $data[$v] ) && $data[$v] !== '' ){
function render( $data , $__showPage = NULL , $layout = NULL , $layoutTpl = true ){ $return[trim($v)] = $data[$v];
$__showPage = strtolower( $__showPage); }
if( $layout == NULL ){ }
$layout = 'default'; return $return;
} }
if( isAjax() ){ return isset( $data[$array] )?$data[$array]:false;
$requiteFile = ROOT.'themes/'.$layout.'/ajax/'.$__showPage.'.tpl.html'; }
}else{ function render( $data , $__showPage = NULL , $layout = NULL , $layoutTpl = true ){
$requiteFile = ROOT.'themes/'.$layout.'/'.($layoutTpl?'layout':$__showPage).'.tpl.html'; $__showPage = strtolower( $__showPage);
} if( $layout == NULL ){
if( !is_file( $requiteFile ) ){ $layout = 'default';
die('can\'t load themes '.$__showPage.' files '); }
} if( isAjax() ){
@extract( $data ); $requiteFile = ROOT.'themes/'.$layout.'/ajax/'.$__showPage.'.tpl.html';
require( $requiteFile ); }else{
} $requiteFile = ROOT.'themes/'.$layout.'/'.($layoutTpl?'layout':$__showPage).'.tpl.html';
if(!function_exists('apache_request_headers')) { }
function apache_request_headers(){ if( !is_file( $requiteFile ) ){
foreach($_SERVER as $key=>$value){ die('can\'t load themes '.$__showPage.' files ');
if (substr($key,0,5)=="HTTP_") { }
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5))))); @extract( $data );
$out[$key]=$value; require( $requiteFile );
} }
} if(!function_exists('apache_request_headers')) {
return $out; function apache_request_headers(){
} foreach($_SERVER as $key=>$value){
} if (substr($key,0,5)=="HTTP_") {
function safeUrlString( $str ){ $key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$str = urldecode($str); $out[$key]=$value;
return str_replace( array( '.' , '/' ) , array() , $str ); }
}
return $out;
}
}
function safeUrlString( $str ){
$str = urldecode($str);
return str_replace( array( '.' , '/' ) , array() , $str );
} }