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

121 lines
4.1KB

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