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

101 lines
3.8KB

  1. <?php
  2. /**
  3. * 图片选择
  4. *
  5. * @version $Id: select_images_post.php 1 9:43 2010年7月8日Z tianya $
  6. * @package DedeBIZ.Dialog
  7. * @copyright Copyright (c) 2021, 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");
  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. $filename_name = $cuserLogin->getUserID() . '-' . dd2char(MyDate("ymdHis", $nowtme) . mt_rand(100, 999));
  47. $filename = $mdir . '/' . $filename_name;
  48. $fs = explode('.', $imgfile_name);
  49. $filename = $filename . '.' . $fs[count($fs) - 1];
  50. $filename_name = $filename_name . '.' . $fs[count($fs) - 1];
  51. $fullfilename = $cfg_basedir . $activepath . "/" . $filename;
  52. move_uploaded_file($imgfile, $fullfilename) or die("上传文件到 $fullfilename 失败!");
  53. @unlink($imgfile);
  54. if (empty($resize)) {
  55. $resize = 0;
  56. }
  57. if ($resize == 1) {
  58. if (in_array($imgfile_type, $cfg_photo_typenames)) {
  59. ImageResize($fullfilename, $iwidth, $iheight);
  60. }
  61. } else {
  62. if (in_array($imgfile_type, $cfg_photo_typenames)) {
  63. WaterImg($fullfilename, 'up');
  64. }
  65. }
  66. $info = '';
  67. $sizes[0] = 0;
  68. $sizes[1] = 0;
  69. $sizes = getimagesize($fullfilename, $info);
  70. $imgwidthValue = $sizes[0];
  71. $imgheightValue = $sizes[1];
  72. $imgsize = filesize($fullfilename);
  73. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  74. VALUES ('0','$filename','" . $activepath . "/" . $filename . "','1','$imgwidthValue','$imgheightValue','0','{$imgsize}','{$nowtme}','" . $cuserLogin->getUserID() . "'); ";
  75. $dsql->ExecuteNoneQuery($inquery);
  76. $fid = $dsql->GetLastID();
  77. AddMyAddon($fid, $activepath . '/' . $filename);
  78. $CKUpload = isset($CKUpload) ? $CKUpload : FALSE;
  79. if ($GLOBALS['cfg_html_editor'] == 'ckeditor' && $CKUpload) {
  80. $fileurl = $activepath . '/' . $filename;
  81. $result = array('url' => $fileurl, "uploaded" => 1, 'fileName' => $filename);
  82. echo json_encode($result);
  83. exit;
  84. }
  85. if (!empty($noeditor)) {
  86. ShowMsg("成功上传一幅图片!", "select_images.php?imgstick=$imgstick&comeback=" . urlencode($filename_name) . "&v=$v&f=$f&CKEditorFuncNum=$CKEditorFuncNum&noeditor=yes&activepath=" . urlencode($activepath) . "/$mdir&d=" . time());
  87. } else {
  88. ShowMsg("成功上传一幅图片!", "select_images.php?imgstick=$imgstick&comeback=" . urlencode($filename_name) . "&v=$v&f=$f&CKEditorFuncNum=$CKEditorFuncNum&activepath=" . urlencode($activepath) . "/$mdir&d=" . time());
  89. }
  90. exit();