中国专业的PHP网站内容管理系统-织梦内容管理系统
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.

62 lines
1.9KB

  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. $GLOBALS['cfg_html_editor']=='ckeditor4' && isset($_FILES['upload'])
  10. )
  11. {
  12. $_FILES['imgfile'] = $_FILES['upload'];
  13. $CKUpload = TRUE;
  14. unset($_FILES['upload']);
  15. }
  16. foreach($_FILES as $_key=>$_value)
  17. {
  18. foreach($keyarr as $k)
  19. {
  20. if(!isset($_FILES[$_key][$k]))
  21. {
  22. exit('Request Error!');
  23. }
  24. }
  25. if( preg_match('#^(cfg_|GLOBALS)#', $_key) )
  26. {
  27. exit('Request var not allow for uploadsafe!');
  28. }
  29. $$_key = $_FILES[$_key]['tmp_name'];
  30. ${$_key.'_name'} = $_FILES[$_key]['name'];
  31. ${$_key.'_type'} = $_FILES[$_key]['type'] = preg_replace('#[^0-9a-z\./]#i', '', $_FILES[$_key]['type']);
  32. ${$_key.'_size'} = $_FILES[$_key]['size'] = preg_replace('#[^0-9]#','',$_FILES[$_key]['size']);
  33. if(!empty(${$_key.'_name'}) && (preg_match("#\.(".$cfg_not_allowall.")$#i",${$_key.'_name'}) || !preg_match("#\.#", ${$_key.'_name'})) )
  34. {
  35. if(!defined('DEDEADMIN'))
  36. {
  37. exit('Not Admin Upload filetype not allow !');
  38. }
  39. }
  40. if(empty(${$_key.'_size'}))
  41. {
  42. ${$_key.'_size'} = @filesize($$_key);
  43. }
  44. $imtypes = array
  45. (
  46. "image/pjpeg", "image/jpeg", "image/gif", "image/png",
  47. "image/xpng", "image/wbmp", "image/bmp"
  48. );
  49. if(in_array(strtolower(trim(${$_key.'_type'})), $imtypes))
  50. {
  51. $image_dd = @getimagesize($$_key);
  52. if (!is_array($image_dd))
  53. {
  54. exit('Upload filetype not allow !');
  55. }
  56. }
  57. }
  58. ?>