国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2KB

  1. <?php
  2. if(!defined('DEDEINC')) exit('Request Error!');
  3. if(isset($_FILES['GLOBALS'])) exit('Request not allow!');
  4. //为了防止用户通过注入的可能性改动了数据库
  5. //这里强制限定的某些文件类型禁止上传
  6. $cfg_not_allowall = "php|pl|cgi|asp|aspx|jsp|php3|shtm|shtml";
  7. $keyarr = array('name', 'type', 'tmp_name', 'size');
  8. if ($GLOBALS['cfg_html_editor']=='ckeditor' && isset($_FILES['upload']))
  9. {
  10. $_FILES['imgfile'] = $_FILES['upload'];
  11. $CKUpload = TRUE;
  12. unset($_FILES['upload']);
  13. }
  14. foreach($_FILES as $_key=>$_value)
  15. {
  16. foreach($keyarr as $k)
  17. {
  18. if(!isset($_FILES[$_key][$k]))
  19. {
  20. exit('Request Error!');
  21. }
  22. }
  23. if( preg_match('#^(cfg_|GLOBALS)#', $_key) )
  24. {
  25. exit('Request var not allow for uploadsafe!');
  26. }
  27. $$_key = $_FILES[$_key]['tmp_name'];
  28. ${$_key.'_name'} = $_FILES[$_key]['name'];
  29. ${$_key.'_type'} = $_FILES[$_key]['type'] = preg_replace('#[^0-9a-z\./]#i', '', $_FILES[$_key]['type']);
  30. ${$_key.'_size'} = $_FILES[$_key]['size'] = preg_replace('#[^0-9]#','',$_FILES[$_key]['size']);
  31. if(!empty(${$_key.'_name'}) && (preg_match("#\.(".$cfg_not_allowall.")$#i",${$_key.'_name'}) || !preg_match("#\.#", ${$_key.'_name'})) )
  32. {
  33. if(!defined('DEDEADMIN'))
  34. {
  35. exit('Not Admin Upload filetype not allow !');
  36. }
  37. }
  38. if(empty(${$_key.'_size'}))
  39. {
  40. ${$_key.'_size'} = @filesize($$_key);
  41. }
  42. $imtypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/bmp"); if(in_array(strtolower(trim(${$_key.'_type'})), $imtypes)) { $image_dd = @getimagesize($$_key); if($image_dd == false){ continue; } if (!is_array($image_dd)) { exit('Upload filetype not allow !'); } }
  43. $imtypes = array
  44. (
  45. "image/pjpeg", "image/jpeg", "image/gif", "image/png",
  46. "image/xpng", "image/wbmp", "image/bmp"
  47. );
  48. if(in_array(strtolower(trim(${$_key.'_type'})), $imtypes))
  49. {
  50. $image_dd = @getimagesize($$_key); if($image_dd == false){ continue; }
  51. if (!is_array($image_dd))
  52. {
  53. exit('Upload filetype not allow !');
  54. }
  55. }
  56. }
  57. ?>