|
@@ -32,20 +32,20 @@ class Core
|
|
|
protected $base = '';
|
|
|
|
|
|
/**
|
|
|
- * __construct
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * __construct
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
public function __construct($data = array())
|
|
|
{
|
|
|
$this->data = $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取根目录
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 获取根目录
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
protected function root()
|
|
|
{
|
|
|
if (!$this->base) {
|
|
@@ -57,10 +57,10 @@ class Core
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 验证数据
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 验证数据
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function check($param)
|
|
|
{
|
|
|
foreach ($param as $k => $v) {
|
|
@@ -74,10 +74,10 @@ class Core
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 验证key是否包含有后续处理的方法
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 验证key是否包含有后续处理的方法
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function check_handle()
|
|
|
{
|
|
|
if (isset($this->data['key']) && strpos($this->data['key'], '_') !== false) {
|
|
@@ -91,10 +91,10 @@ class Core
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 验证文件是否存在
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 验证文件是否存在
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function check_file()
|
|
|
{
|
|
|
if ($this->data['file']['tmp_name'] == '') {
|
|
@@ -104,10 +104,10 @@ class Core
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 验证基本配置
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 验证基本配置
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function check_key()
|
|
|
{
|
|
|
if (trim($this->data['key']) == '') {
|
|
@@ -124,10 +124,10 @@ class Core
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 验证文件类型
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 验证文件类型
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function check_type()
|
|
|
{
|
|
|
$ext = $this->getExt($this->data['file']['tmp_name']);
|
|
@@ -140,10 +140,10 @@ class Core
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 验证文件大小
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 验证文件大小
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function check_size()
|
|
|
{
|
|
|
if ($this->config['width'] > 0 || $this->config['height'] > 0) {
|
|
@@ -168,10 +168,10 @@ class Core
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 上传操作
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * 上传操作
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
public function copy()
|
|
|
{
|
|
|
$this->output['status'] = 1;
|
|
@@ -280,13 +280,196 @@ class Core
|
|
|
|
|
|
Dever::load('upload/file-insert', $param);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * getExt
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
+ * getExt
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
protected function getExt($filename)
|
|
|
+ {
|
|
|
+ if (!function_exists('finfo_open')) {
|
|
|
+ return $this->getExtByByte($filename);
|
|
|
+ }
|
|
|
+ $finfo = finfo_open(FILEINFO_MIME); // 返回 mime 类型
|
|
|
+ $code = finfo_file($finfo, $filename);
|
|
|
+ finfo_close($finfo);
|
|
|
+ $temp = explode(';', $code);
|
|
|
+ $ext = $this->getExtByMine($temp[0]);
|
|
|
+ if (!$ext || $ext == 'txt') {
|
|
|
+ $ext = $this->getExtByByte($filename);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $ext;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据mime类型获取文件扩展名
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ protected function getExtByMine($mine)
|
|
|
+ {
|
|
|
+ $mine = trim($mine);
|
|
|
+ $config = array
|
|
|
+ (
|
|
|
+ 'application/envoy' => 'evy',
|
|
|
+ 'application/fractals' => 'fif',
|
|
|
+ 'application/futuresplash' => 'spl',
|
|
|
+ 'application/hta' => 'hta',
|
|
|
+ 'application/internet-property-stream' => 'acx',
|
|
|
+ 'application/mac-binhex40' => 'hqx',
|
|
|
+ 'application/msword' => 'doc',
|
|
|
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
|
|
|
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
|
|
|
+ 'video/x-m4v' => 'mp4',
|
|
|
+ 'application/octet-stream' => 'exe',
|
|
|
+ 'application/oda' => 'oda',
|
|
|
+ 'application/olescript' => 'axs',
|
|
|
+ 'application/pdf' => 'pdf',
|
|
|
+ 'application/pics-rules' => 'prf',
|
|
|
+ 'application/pkcs10' => 'p10',
|
|
|
+ 'application/pkix-crl' => 'crl',
|
|
|
+ 'application/postscript' => 'ai',
|
|
|
+ 'application/postscript' => 'eps',
|
|
|
+ 'application/postscript' => 'ps',
|
|
|
+ 'application/rtf' => 'rtf',
|
|
|
+ 'application/set-payment-initiation' => 'setpay',
|
|
|
+ 'application/set-registration-initiation' => 'setreg',
|
|
|
+ 'application/vnd.ms-excel' => 'xls',
|
|
|
+ 'application/vnd.ms-outlook' => 'msg',
|
|
|
+ 'application/vnd.ms-pkicertstore' => 'sst',
|
|
|
+ 'application/vnd.ms-pkiseccat' => 'cat',
|
|
|
+ 'application/vnd.ms-pkistl' => 'stl',
|
|
|
+ 'application/vnd.ms-powerpoint' => 'ppt',
|
|
|
+ 'application/vnd.ms-project' => 'mpp',
|
|
|
+ 'application/vnd.ms-works' => 'wps',
|
|
|
+ 'application/winhlp' => 'hlp',
|
|
|
+ 'application/x-bcpio' => 'bcpio',
|
|
|
+ 'application/x-cdf' => 'cdf',
|
|
|
+ 'application/x-compress' => 'z',
|
|
|
+ 'application/x-compressed' => 'tgz',
|
|
|
+ 'application/x-cpio' => 'cpio',
|
|
|
+ 'application/x-csh' => 'csh',
|
|
|
+ 'application/x-director' => 'dir',
|
|
|
+ 'application/x-dvi' => 'dvi',
|
|
|
+ 'application/x-gtar' => 'gtar',
|
|
|
+ 'application/x-gzip' => 'gz',
|
|
|
+ 'application/x-hdf' => 'hdf',
|
|
|
+ 'application/x-internet-signup' => 'isp',
|
|
|
+ 'application/x-iphone' => 'iii',
|
|
|
+ 'application/x-javascript' => 'js',
|
|
|
+ 'application/x-latex' => 'latex',
|
|
|
+ 'application/x-msaccess' => 'mdb',
|
|
|
+ 'application/x-mscardfile' => 'crd',
|
|
|
+ 'application/x-msclip' => 'clp',
|
|
|
+ 'application/x-msdownload' => 'dll',
|
|
|
+ 'application/x-msmediaview' => 'mvb',
|
|
|
+ 'application/x-msmetafile' => 'wmf',
|
|
|
+ 'application/x-msmoney' => 'mny',
|
|
|
+ 'application/x-mspublisher' => 'pub',
|
|
|
+ 'application/x-msschedule' => 'scd',
|
|
|
+ 'application/x-msterminal' => 'trm',
|
|
|
+ 'application/x-mswrite' => 'wri',
|
|
|
+ 'application/x-netcdf' => 'cdf',
|
|
|
+ 'application/x-netcdf' => 'nc',
|
|
|
+ 'application/x-perfmon' => 'pma',
|
|
|
+ 'application/x-pkcs12' => 'p12',
|
|
|
+ 'application/x-pkcs12' => 'pfx',
|
|
|
+ 'application/x-pkcs7-certificates' => 'p7b',
|
|
|
+ 'application/x-pkcs7-certreqresp' => 'p7r',
|
|
|
+ 'application/x-pkcs7-mime' => 'p7c',
|
|
|
+ 'application/x-pkcs7-signature' => 'p7s',
|
|
|
+ 'application/x-sh' => 'sh',
|
|
|
+ 'application/x-shar' => 'shar',
|
|
|
+ 'application/x-shockwave-flash' => 'swf',
|
|
|
+ 'application/x-stuffit' => 'sit',
|
|
|
+ 'application/x-sv4cpio' => 'sv4cpio',
|
|
|
+ 'application/x-sv4crc' => 'sv4crc',
|
|
|
+ 'application/x-tar' => 'tar',
|
|
|
+ 'application/x-tcl' => 'tcl',
|
|
|
+ 'application/x-tex' => 'tex',
|
|
|
+ 'application/x-texinfo' => 'texi',
|
|
|
+ 'application/x-texinfo' => 'texinfo',
|
|
|
+ 'application/x-troff' => 'roff',
|
|
|
+ 'application/x-troff' => 't',
|
|
|
+ 'application/x-troff' => 'tr',
|
|
|
+ 'application/x-troff-man' => 'man',
|
|
|
+ 'application/x-troff-me' => 'me',
|
|
|
+ 'application/x-troff-ms' => 'ms',
|
|
|
+ 'application/x-ustar' => 'ustar',
|
|
|
+ 'application/x-wais-source' => 'src',
|
|
|
+ 'application/x-x509-ca-cert' => 'cer',
|
|
|
+ 'application/ynd.ms-pkipko' => 'pko',
|
|
|
+ 'application/zip' => 'zip',
|
|
|
+ 'audio/basic' => 'au',
|
|
|
+ 'audio/basic' => 'snd',
|
|
|
+ 'audio/mid' => 'mid',
|
|
|
+ 'audio/mid' => 'rmi',
|
|
|
+ 'audio/mpeg' => 'mp3',
|
|
|
+ 'audio/x-aiff' => 'aif',
|
|
|
+ 'audio/x-aiff' => 'aifc',
|
|
|
+ 'audio/x-aiff' => 'aiff',
|
|
|
+ 'audio/x-mpegurl' => 'm3u',
|
|
|
+ 'audio/x-pn-realaudio' => 'ram',
|
|
|
+ 'audio/x-wav' => 'wav',
|
|
|
+ 'image/bmp' => 'bmp',
|
|
|
+ 'image/cis-cod' => 'cod',
|
|
|
+ 'image/gif' => 'gif',
|
|
|
+ 'image/ief' => 'ief',
|
|
|
+ 'image/jpeg' => 'jpg',
|
|
|
+ 'image/pipeg' => 'jfif',
|
|
|
+ 'image/svg+xml' => 'svg',
|
|
|
+ 'image/tiff' => 'tif',
|
|
|
+ 'image/tiff' => 'tiff',
|
|
|
+ 'image/x-cmu-raster' => 'ras',
|
|
|
+ 'image/x-cmx' => 'cmx',
|
|
|
+ 'image/x-icon' => 'ico',
|
|
|
+ 'image/x-portable-anymap' => 'pnm',
|
|
|
+ 'image/x-portable-bitmap' => 'pbm',
|
|
|
+ 'image/x-portable-graymap' => 'pgm',
|
|
|
+ 'image/x-portable-pixmap' => 'ppm',
|
|
|
+ 'image/x-rgb' => 'rgb',
|
|
|
+ 'image/x-xbitmap' => 'xbm',
|
|
|
+ 'image/x-xpixmap' => 'xpm',
|
|
|
+ 'image/x-xwindowdump' => 'xwd',
|
|
|
+ 'message/rfc822' => 'mht',
|
|
|
+ 'message/rfc822' => 'mhtml',
|
|
|
+ 'message/rfc822' => 'nws',
|
|
|
+ 'text/css' => 'css',
|
|
|
+ 'text/h323' => '323',
|
|
|
+ 'text/html' => 'html',
|
|
|
+ 'text/iuls' => 'uls',
|
|
|
+ 'text/plain' => 'txt',
|
|
|
+ 'text/richtext' => 'rtx',
|
|
|
+ 'text/scriptlet' => 'sct',
|
|
|
+ 'text/tab-separated-values' => 'tsv',
|
|
|
+ 'text/webviewhtml' => 'htt',
|
|
|
+ 'text/x-component' => 'htc',
|
|
|
+ 'text/x-setext' => 'etx',
|
|
|
+ 'text/x-vcard' => 'vcf',
|
|
|
+ 'video/mpeg' => 'mpeg',
|
|
|
+ 'video/quicktime' => 'mov',
|
|
|
+ 'video/x-ms-asf' => 'asx',
|
|
|
+ 'video/x-msvideo' => 'avi',
|
|
|
+ 'video/x-sgi-movie' => 'movie',
|
|
|
+ 'x-world/x-vrml' => 'flr',
|
|
|
+ 'application/x-rar' => 'rar',
|
|
|
+ );
|
|
|
+
|
|
|
+ if (isset($config[$mine])) {
|
|
|
+ return $config[$mine];
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * getExt 已废弃
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ protected function getExtByByte($filename)
|
|
|
{
|
|
|
$file = fopen($filename,"rb");
|
|
|
$bin = fread($file,2);
|
|
@@ -297,50 +480,53 @@ class Core
|
|
|
switch ($typeCode) {
|
|
|
case 7790:
|
|
|
$fileType = 'exe';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 7784:
|
|
|
$fileType = 'midi';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 8297:
|
|
|
$fileType = 'rar';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 255216:
|
|
|
$fileType = 'jpg';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 7173:
|
|
|
$fileType = 'gif';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 13780:
|
|
|
$fileType = 'png';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 6677:
|
|
|
$fileType = 'bmp';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 6787:
|
|
|
$fileType = 'swf';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 6063;
|
|
|
$fileType = 'php|xml';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 6033:
|
|
|
$fileType = 'html|htm|shtml';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 8075:
|
|
|
$fileType = 'zip';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 6782:
|
|
|
case 1310:
|
|
|
$fileType = 'txt';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 4742:
|
|
|
$fileType = 'js';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 8273:
|
|
|
$fileType = 'wav';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 7368:
|
|
|
$fileType = 'mp3';
|
|
|
- break;
|
|
|
+ break;
|
|
|
+ case 3780:
|
|
|
+ $fileType = 'pdf';
|
|
|
+ break;
|
|
|
default:
|
|
|
$fileType = 'unknown'.$typeCode;
|
|
|
break;
|
|
@@ -354,6 +540,7 @@ class Core
|
|
|
if ($strInfo['chars1'] == '-48' && $strInfo['chars2'] == '-49') {
|
|
|
return 'msi';
|
|
|
}
|
|
|
+
|
|
|
return $fileType;
|
|
|
}
|
|
|
}
|