国内流行的内容管理系统(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.

100 lines
4.1KB

  1. <?php
  2. /**
  3. * 图片选择
  4. *
  5. * @version $id:select_images_post.php 9:43 2010年7月8日 tianya $
  6. * @package DedeBIZ.Dialog
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__)."/config.php");
  12. require_once(DEDEINC."/image.func.php");
  13. if (empty($activepath)) {
  14. $activepath = '';
  15. $activepath = str_replace('.', '', $activepath);
  16. $activepath = preg_replace("#\/{1,}#", '/', $activepath);
  17. if (strlen($activepath) < strlen($cfg_image_dir)) {
  18. $activepath = $cfg_image_dir;
  19. }
  20. }
  21. if (empty($imgfile)) {
  22. $imgfile = '';
  23. }
  24. if (!is_uploaded_file($imgfile)) {
  25. ShowMsg("您没有选择上传的文件".$imgfile, "-1");
  26. exit();
  27. }
  28. $CKEditorFuncNum = (isset($CKEditorFuncNum)) ? $CKEditorFuncNum : 1;
  29. $imgfile_name = trim(preg_replace("#[ \r\n\t\*\%\\\/\?><\|\":]{1,}#", '', $imgfile_name));
  30. if (!preg_match("#\.(".$cfg_imgtype.")#i", $imgfile_name)) {
  31. ShowMsg("您所上传的图片类型不在许可列表,请修改系统对扩展名限定的配置", "-1");
  32. exit();
  33. }
  34. $nowtme = time();
  35. $sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/webp");
  36. $imgfile_type = strtolower(trim($imgfile_type));
  37. if (!in_array($imgfile_type, $sparr)) {
  38. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG、WBMP格式的其中一种", "-1");
  39. exit();
  40. }
  41. $mdir = MyDate($cfg_addon_savetype, $nowtme);
  42. if (!is_dir($cfg_basedir.$activepath."/$mdir")) {
  43. MkdirAll($cfg_basedir.$activepath."/$mdir", $cfg_dir_purview);
  44. CloseFtp();
  45. }
  46. $iseditor = isset($iseditor)? intval($iseditor) : 0;
  47. $filename_name = $cuserLogin->getUserID().'-'.dd2char(MyDate("ymdHis", $nowtme).mt_rand(100, 999));
  48. $filename = $mdir.'/'.$filename_name;
  49. $fs = explode('.', $imgfile_name);
  50. $filename = $filename.'.'.$fs[count($fs) - 1];
  51. $filename_name = $filename_name.'.'.$fs[count($fs) - 1];
  52. $fullfilename = $cfg_basedir.$activepath."/".$filename;
  53. $mime = get_mime_type($imgfile);
  54. if (preg_match("#^unknow#", $mime)) {
  55. ShowMsg("系统不支持fileinfo组件,建议php.ini中开启", -1);
  56. exit;
  57. }
  58. if (!preg_match("#^(image|video|audio|application)#i", $mime)) {
  59. ShowMsg("仅支持媒体文件及应用程序上传", -1);
  60. exit;
  61. }
  62. move_uploaded_file($imgfile, $fullfilename) or die("上传文件到<span class='text-primary'>$fullfilename</span>失败");
  63. @unlink($imgfile);
  64. if (empty($resize)) {
  65. $resize = 0;
  66. }
  67. if ($resize == 1) {
  68. if (in_array($imgfile_type, $cfg_photo_typenames)) {
  69. ImageResize($fullfilename, $iwidth, $iheight);
  70. }
  71. } else {
  72. if (in_array($imgfile_type, $cfg_photo_typenames)) {
  73. WaterImg($fullfilename, 'up');
  74. }
  75. }
  76. $info = '';
  77. $sizes[0] = 0;
  78. $sizes[1] = 0;
  79. $sizes = getimagesize($fullfilename, $info);
  80. $imgwidthValue = $sizes[0];
  81. $imgheightValue = $sizes[1];
  82. $imgsize = filesize($fullfilename);
  83. $inquery = "INSERT INTO `#@__uploads` (arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ('0','$filename','".$activepath."/".$filename."','1','$imgwidthValue','$imgheightValue','0','{$imgsize}','{$nowtme}','".$cuserLogin->getUserID()."'); ";
  84. $dsql->ExecuteNoneQuery($inquery);
  85. $fid = $dsql->GetLastID();
  86. AddMyAddon($fid, $activepath.'/'.$filename);
  87. $CKUpload = isset($CKUpload) ? $CKUpload : FALSE;
  88. if ($GLOBALS['cfg_html_editor'] == 'ckeditor' && $CKUpload) {
  89. $fileurl = $activepath.'/'.$filename;
  90. $result = array('url' => $fileurl, "uploaded" => 1, 'fileName' => $filename);
  91. echo json_encode($result);
  92. exit;
  93. }
  94. if (!empty($noeditor)) {
  95. ShowMsg("成功上传一张图片", "select_images.php?iseditor=$iseditor&imgstick=$imgstick&comeback=".urlencode($filename_name)."&v=$v&f=$f&CKEditorFuncNum=$CKEditorFuncNum&noeditor=yes&activepath=".urlencode($activepath)."/$mdir&d=".time());
  96. } else {
  97. ShowMsg("成功上传一张图片", "select_images.php?iseditor=$iseditor&imgstick=$imgstick&comeback=".urlencode($filename_name)."&v=$v&f=$f&CKEditorFuncNum=$CKEditorFuncNum&activepath=".urlencode($activepath)."/$mdir&d=".time());
  98. }
  99. exit();
  100. ?>