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

122 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 DedeCMS.Dialog
  7. * @copyright Copyright (c) 2007 - 2018, DesDev, Inc.
  8. * @copyright Copyright (c) 2020, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license/v6
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(dirname(__FILE__)."/config.php");
  13. require_once(DEDEINC."/image.func.php");
  14. if(empty($activepath))
  15. {
  16. $activepath ='';
  17. $activepath = str_replace('.', '', $activepath);
  18. $activepath = preg_replace("#\/{1,}#", '/', $activepath);
  19. if(strlen($activepath) < strlen($cfg_image_dir))
  20. {
  21. $activepath = $cfg_image_dir;
  22. }
  23. }
  24. if(empty($imgfile))
  25. {
  26. $imgfile='';
  27. }
  28. if(!is_uploaded_file($imgfile))
  29. {
  30. ShowMsg("你没有选择上传的文件!".$imgfile, "-1");
  31. exit();
  32. }
  33. $CKEditorFuncNum = (isset($CKEditorFuncNum))? $CKEditorFuncNum : 1;
  34. $imgfile_name = trim(preg_replace("#[ \r\n\t\*\%\\\/\?><\|\":]{1,}#", '', $imgfile_name));
  35. if(!preg_match("#\.(".$cfg_imgtype.")#i", $imgfile_name))
  36. {
  37. ShowMsg("你所上传的图片类型不在许可列表,请更改系统对扩展名限定的配置!", "-1");
  38. exit();
  39. }
  40. $nowtme = time();
  41. $sparr = Array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp");
  42. $imgfile_type = strtolower(trim($imgfile_type));
  43. if(!in_array($imgfile_type, $sparr))
  44. {
  45. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG、WBMP格式的其中一种!","-1");
  46. exit();
  47. }
  48. $mdir = MyDate($cfg_addon_savetype, $nowtme);
  49. if(!is_dir($cfg_basedir.$activepath."/$mdir"))
  50. {
  51. MkdirAll($cfg_basedir.$activepath."/$mdir",$cfg_dir_purview);
  52. CloseFtp();
  53. }
  54. $filename_name = $cuserLogin->getUserID().'-'.dd2char(MyDate("ymdHis", $nowtme).mt_rand(100,999));
  55. $filename = $mdir.'/'.$filename_name;
  56. $fs = explode('.', $imgfile_name);
  57. $filename = $filename.'.'.$fs[count($fs)-1];
  58. $filename_name = $filename_name.'.'.$fs[count($fs)-1];
  59. $fullfilename = $cfg_basedir.$activepath."/".$filename;
  60. move_uploaded_file($imgfile, $fullfilename) or die("上传文件到 $fullfilename 失败!");
  61. if($cfg_remote_site=='Y' && $remoteuploads == 1)
  62. {
  63. //分析远程文件路径
  64. $remotefile = str_replace(DEDEROOT, '', $fullfilename);
  65. $localfile = '../..'.$remotefile;
  66. //创建远程文件夹
  67. $remotedir = preg_replace('/[^\/]*\.(jpg|gif|bmp|png)/', '', $remotefile);
  68. $ftp->rmkdir($remotedir);
  69. $ftp->upload($localfile, $remotefile);
  70. }
  71. @unlink($imgfile);
  72. if(empty($resize))
  73. {
  74. $resize = 0;
  75. }
  76. if($resize==1)
  77. {
  78. if(in_array($imgfile_type, $cfg_photo_typenames))
  79. {
  80. ImageResize($fullfilename, $iwidth, $iheight);
  81. }
  82. }
  83. else
  84. {
  85. if(in_array($imgfile_type, $cfg_photo_typenames))
  86. {
  87. WaterImg($fullfilename, 'up');
  88. }
  89. }
  90. $info = '';
  91. $sizes[0] = 0; $sizes[1] = 0;
  92. $sizes = getimagesize($fullfilename, $info);
  93. $imgwidthValue = $sizes[0];
  94. $imgheightValue = $sizes[1];
  95. $imgsize = filesize($fullfilename);
  96. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  97. VALUES ('0','$filename','".$activepath."/".$filename."','1','$imgwidthValue','$imgheightValue','0','{$imgsize}','{$nowtme}','".$cuserLogin->getUserID()."'); ";
  98. $dsql->ExecuteNoneQuery($inquery);
  99. $fid = $dsql->GetLastID();
  100. AddMyAddon($fid, $activepath.'/'.$filename);
  101. $CKUpload = isset($CKUpload)? $CKUpload : FALSE;
  102. if ($GLOBALS['cfg_html_editor']=='ckeditor' && $CKUpload)
  103. {
  104. $fileurl = $activepath.'/'.$filename;
  105. $result = array('url' => $fileurl,"uploaded"=>1,'fileName'=>$filename);
  106. echo json_encode($result);
  107. exit;
  108. }
  109. if(!empty($noeditor)){
  110. ShowMsg("成功上传一幅图片!","select_images.php?imgstick=$imgstick&comeback=".urlencode($filename_name)."&v=$v&f=$f&CKEditorFuncNum=$CKEditorFuncNum&noeditor=yes&activepath=".urlencode($activepath)."/$mdir&d=".time());
  111. }else{
  112. ShowMsg("成功上传一幅图片!","select_images.php?imgstick=$imgstick&comeback=".urlencode($filename_name)."&v=$v&f=$f&CKEditorFuncNum=$CKEditorFuncNum&activepath=".urlencode($activepath)."/$mdir&d=".time());
  113. }
  114. exit();