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

109 lines
4.2KB

  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. if ($cfg_remote_site == 'Y' && $remoteuploads == 1) {
  54. //分析远程文件路径
  55. $remotefile = str_replace(DEDEROOT, '', $fullfilename);
  56. $localfile = '../..' . $remotefile;
  57. //创建远程文件夹
  58. $remotedir = preg_replace('/[^\/]*\.(jpg|gif|bmp|png)/', '', $remotefile);
  59. $ftp->rmkdir($remotedir);
  60. $ftp->upload($localfile, $remotefile);
  61. }
  62. @unlink($imgfile);
  63. if (empty($resize)) {
  64. $resize = 0;
  65. }
  66. if ($resize == 1) {
  67. if (in_array($imgfile_type, $cfg_photo_typenames)) {
  68. ImageResize($fullfilename, $iwidth, $iheight);
  69. }
  70. } else {
  71. if (in_array($imgfile_type, $cfg_photo_typenames)) {
  72. WaterImg($fullfilename, 'up');
  73. }
  74. }
  75. $info = '';
  76. $sizes[0] = 0;
  77. $sizes[1] = 0;
  78. $sizes = getimagesize($fullfilename, $info);
  79. $imgwidthValue = $sizes[0];
  80. $imgheightValue = $sizes[1];
  81. $imgsize = filesize($fullfilename);
  82. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  83. 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?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?imgstick=$imgstick&comeback=" . urlencode($filename_name) . "&v=$v&f=$f&CKEditorFuncNum=$CKEditorFuncNum&activepath=" . urlencode($activepath) . "/$mdir&d=" . time());
  98. }
  99. exit();