国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

120 líneas
4.3KB

  1. <?php
  2. /**
  3. * 文件上传安全校验方法
  4. *
  5. * @version $Id: uploadsafe.inc.php 1 15:59 2020年8月19日Z tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2007 - 2018, DesDev, Inc.
  8. * @copyright Copyright (c) 2020, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license/v6
  10. * @link https://www.dedebiz.com
  11. */
  12. if (!defined('DEDEINC')) exit('Request Error!');
  13. if (isset($_FILES['GLOBALS'])) exit('Request not allow!');
  14. //为了防止用户通过注入的可能性改动了数据库
  15. //这里强制限定的某些文件类型禁止上传
  16. $cfg_not_allowall = "php|pl|cgi|asp|aspx|jsp|php3|shtm|shtml";
  17. $keyarr = array('name', 'type', 'tmp_name', 'size');
  18. if (
  19. ($GLOBALS['cfg_html_editor'] == 'ckeditor' ||
  20. $GLOBALS['cfg_html_editor'] == 'ckeditor4') && isset($_FILES['upload'])
  21. ) {
  22. $_FILES['imgfile'] = $_FILES['upload'];
  23. $CKUpload = TRUE;
  24. unset($_FILES['upload']);
  25. }
  26. foreach ($_FILES as $_key => $_value) {
  27. foreach ($keyarr as $k) {
  28. if (!isset($_FILES[$_key][$k])) {
  29. exit('Request Error!');
  30. }
  31. }
  32. if (preg_match('#^(cfg_|GLOBALS)#', $_key)) {
  33. exit('Request var not allow for uploadsafe!');
  34. }
  35. $$_key = $_FILES[$_key]['tmp_name'];
  36. ${$_key . '_name'} = $_FILES[$_key]['name'];
  37. ${$_key . '_type'} = $_FILES[$_key]['type'] = preg_replace('#[^0-9a-z\./]#i', '', $_FILES[$_key]['type']);
  38. ${$_key . '_size'} = $_FILES[$_key]['size'] = preg_replace('#[^0-9]#', '', $_FILES[$_key]['size']);
  39. if (is_array(${$_key.'_name'}) && count(${$_key.'_name'}) > 0) {
  40. foreach (${$_key.'_name'} as $key => $value) {
  41. if (!empty($value) && (preg_match("#\.(" . $cfg_not_allowall . ")$#i", $value) || !preg_match("#\.#", $value))) {
  42. if (!defined('DEDEADMIN')) {
  43. exit('Not Admin Upload filetype not allow !');
  44. }
  45. }
  46. }
  47. } else {
  48. if (!empty(${$_key . '_name'}) && (preg_match("#\.(" . $cfg_not_allowall . ")$#i", ${$_key . '_name'}) || !preg_match("#\.#", ${$_key . '_name'}))) {
  49. if (!defined('DEDEADMIN')) {
  50. exit('Not Admin Upload filetype not allow !');
  51. }
  52. }
  53. }
  54. if (empty(${$_key . '_size'})) {
  55. ${$_key . '_size'} = @filesize($$_key);
  56. }
  57. $imtypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/bmp");
  58. if (is_array(${$_key.'_type'}) && count(${$_key.'_type'}) > 0) {
  59. foreach (${$_key.'_type'} as $key => $value) {
  60. if (in_array(strtolower(trim($value)), $imtypes)) {
  61. $image_dd = @getimagesize($$_key);
  62. if ($image_dd == false) {
  63. continue;
  64. }
  65. if (!is_array($image_dd)) {
  66. exit('Upload filetype not allow !');
  67. }
  68. }
  69. $imtypes = array(
  70. "image/pjpeg", "image/jpeg", "image/gif", "image/png",
  71. "image/xpng", "image/wbmp", "image/bmp"
  72. );
  73. if (in_array(strtolower(trim($value)), $imtypes)) {
  74. $image_dd = @getimagesize($$_key);
  75. if ($image_dd == false) {
  76. continue;
  77. }
  78. if (!is_array($image_dd)) {
  79. exit('Upload filetype not allow !');
  80. }
  81. }
  82. }
  83. } else {
  84. if (in_array(strtolower(trim(${$_key . '_type'})), $imtypes)) {
  85. $image_dd = @getimagesize($$_key);
  86. if ($image_dd == false) {
  87. continue;
  88. }
  89. if (!is_array($image_dd)) {
  90. exit('Upload filetype not allow !');
  91. }
  92. }
  93. $imtypes = array(
  94. "image/pjpeg", "image/jpeg", "image/gif", "image/png",
  95. "image/xpng", "image/wbmp", "image/bmp"
  96. );
  97. if (in_array(strtolower(trim(${$_key . '_type'})), $imtypes)) {
  98. $image_dd = @getimagesize($$_key);
  99. if ($image_dd == false) {
  100. continue;
  101. }
  102. if (!is_array($image_dd)) {
  103. exit('Upload filetype not allow !');
  104. }
  105. }
  106. }
  107. }