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

  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 GNU GPL v2 (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. define("DEDE_DIALOG_UPLOAD", true);
  14. if (empty($activepath)) {
  15. $activepath = '';
  16. $activepath = str_replace('.', '', $activepath);
  17. $activepath = preg_replace("#\/{1,}#", '/', $activepath);
  18. if (strlen($activepath) < strlen($cfg_image_dir)) {
  19. $activepath = $cfg_image_dir;
  20. }
  21. }
  22. if (empty($imgfile)) {
  23. $imgfile = '';
  24. }
  25. if (!is_uploaded_file($imgfile)) {
  26. ShowMsg("您没有选择上传文件".$imgfile, "-1");
  27. exit();
  28. }
  29. $CKEditorFuncNum = (isset($CKEditorFuncNum)) ? $CKEditorFuncNum : 1;
  30. $imgfile_name = trim(preg_replace("#[ \r\n\t\*\%\\\/\?><\|\":]{1,}#", '', $imgfile_name));
  31. if (!preg_match("#\.(".$cfg_imgtype.")#i", $imgfile_name)) {
  32. ShowMsg("您上传的图片类型错误,请修改系统对扩展名配置", "-1");
  33. exit();
  34. }
  35. $nowtme = time();
  36. $sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/webp");
  37. $imgfile_type = strtolower(trim($imgfile_type));
  38. if (!in_array($imgfile_type, $sparr)) {
  39. ShowMsg("您上传的图片格式错误,请使用jpg、png、gif、wbmp格式其中一种", "-1");
  40. exit();
  41. }
  42. $mdir = MyDate($cfg_addon_savetype, $nowtme);
  43. if (!is_dir($cfg_basedir.$activepath."/$mdir")) {
  44. MkdirAll($cfg_basedir.$activepath."/$mdir", $cfg_dir_purview);
  45. }
  46. $iseditor = isset($iseditor)? intval($iseditor) : 0;
  47. $filename_name = $cuserLogin->getUserID().'-'.dd2char(MyDate("ymdHis", $nowtme).mt_rand(1000, 6000));
  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("上传文件到".$fullfilename."失败");
  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. ?>