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

220 lines
6.7KB

  1. <?php
  2. /**
  3. * 附件编辑
  4. *
  5. * @version $Id: media_edit.php 1 11:17 2010年7月19日Z tianya $
  6. * @package DedeCMS.Administrator
  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. //权限检查
  14. CheckPurview('sys_Upload,sys_MyUpload');
  15. if(empty($dopost)) $dopost = "";
  16. $backurl = isset($_COOKIE['ENV_GOBACK_URL']) ? $_COOKIE['ENV_GOBACK_URL'] : "javascript:history.go(-1);";
  17. /*---------------------------
  18. function __del_file() //删除附件
  19. -----------------------------*/
  20. if($dopost=='del')
  21. {
  22. CheckPurview('sys_DelUpload');
  23. if(empty($ids))
  24. {
  25. $ids="";
  26. }
  27. if($ids=="")
  28. {
  29. $myrow = $dsql->GetOne("SELECT url FROM #@__uploads WHERE aid='".$aid."'");
  30. $truefile = $cfg_basedir.$myrow['url'];
  31. $rs = 0;
  32. if(!file_exists($truefile)||$myrow['url']=="")
  33. {
  34. $rs = 1;
  35. } else {
  36. $rs = @unlink($truefile);
  37. //如果开启远程附件则需要同步删除文件
  38. if($cfg_remote_site=='Y')
  39. {
  40. if($ftp->connect($ftpconfig) && $remoteuploads == 1)
  41. {
  42. $remotefile = str_replace(DEDEROOT, '', $truefile);
  43. $ftp->delete_file($remotefile);
  44. }
  45. }
  46. }
  47. if($rs==1)
  48. {
  49. $msg = "成功删除一个附件!";
  50. $dsql->ExecuteNoneQuery("DELETE FROM #@__uploads WHERE aid='".$aid."'");
  51. }
  52. ShowMsg($msg,$backurl);
  53. exit();
  54. } else {
  55. $ids = explode(',', $ids);
  56. $idquery = "";
  57. foreach($ids as $aid)
  58. {
  59. if($idquery=="")
  60. {
  61. $idquery .= " WHERE aid='$aid' ";
  62. }
  63. else
  64. {
  65. $idquery .= " OR aid='$aid' ";
  66. }
  67. }
  68. $dsql->SetQuery("SELECT aid,url FROM #@__uploads $idquery ");
  69. $dsql->Execute();
  70. //如果开启远程附件则需要同步删除文件
  71. if($cfg_remote_site=='Y' && $remoteuploads == 1)
  72. {
  73. $ftp->connect($ftpconfig);
  74. }
  75. while($myrow=$dsql->GetArray())
  76. {
  77. $truefile = $cfg_basedir.$myrow['url'];
  78. $rs = 0;
  79. if(!file_exists($truefile) || $myrow['url']=="")
  80. {
  81. $rs = 1;
  82. }
  83. else
  84. {
  85. $rs = @unlink($truefile);
  86. if($cfg_remote_site=='Y' && $remoteuploads == 1)
  87. {
  88. $remotefile = str_replace(DEDEROOT, '', $truefile);
  89. $ftp->delete_file($remotefile);
  90. }
  91. }
  92. if($rs==1)
  93. {
  94. $dsql->ExecuteNoneQuery("DELETE FROM #@__uploads WHERE aid='".$myrow['aid']."'");
  95. }
  96. }
  97. ShowMsg('成功删除选定的文件!',$backurl);
  98. exit();
  99. }
  100. }
  101. /*--------------------------------
  102. function __save_edit() //保存更改
  103. -----------------------------------*/
  104. else if($dopost=='save')
  105. {
  106. if($aid=="") exit();
  107. CheckCSRF();
  108. //检查是否有修改权限
  109. $myrow = $dsql->GetOne("SELECT * FROM #@__uploads WHERE aid='".$aid."'");
  110. if($myrow['mid']!=$cuserLogin->getUserID())
  111. {
  112. CheckPurview('sys_Upload');
  113. }
  114. //检测文件类型
  115. $addquery = "";
  116. if(is_uploaded_file($upfile))
  117. {
  118. if($mediatype==1)
  119. {
  120. $sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png","image/xpng","image/wbmp");
  121. if(!in_array($upfile_type,$sparr))
  122. {
  123. ShowMsg("你上传的不是图片类型的文件!","javascript:history.go(-1);");
  124. exit();
  125. }
  126. }
  127. else if($mediatype==2)
  128. {
  129. $sparr = Array("application/x-shockwave-flash");
  130. if(!in_array($upfile_type,$sparr))
  131. {
  132. ShowMsg("你上传的不是Flash类型的文件!","javascript:history.go(-1);");
  133. exit();
  134. }
  135. }else if($mediatype==3)
  136. {
  137. if(!preg_match('#audio|media|video#i', $upfile_type))
  138. {
  139. ShowMsg("你上传的为不正确类型的影音文件!","javascript:history.go(-1);");
  140. exit();
  141. }
  142. if(!preg_match("#\.".$cfg_mediatype."#", $upfile_name))
  143. {
  144. ShowMsg("你上传的影音文件扩展名无法被识别,请更改系统配置的参数!","javascript:history.go(-1);");
  145. exit();
  146. }
  147. }else
  148. {
  149. if(!preg_match("#\.".$cfg_softtype."#", $upfile_name))
  150. {
  151. ShowMsg("你上传的附件扩展名无法被识别,请更改系统配置的参数!","javascript:history.go(-1);");
  152. exit();
  153. }
  154. }
  155. //保存文件
  156. $nowtime = time();
  157. $oldfile = $myrow['url'];
  158. $oldfiles = explode('/', $oldfile);
  159. $fullfilename = $cfg_basedir.$oldfile;
  160. $oldfile_path = preg_replace("#".$oldfiles[count($oldfiles)-1]."$#", "", $oldfile);
  161. if(!is_dir($cfg_basedir.$oldfile_path))
  162. {
  163. MkdirAll($cfg_basedir.$oldfile_path, 777);
  164. CloseFtp();
  165. }
  166. @move_uploaded_file($upfile, $fullfilename);
  167. if($mediatype==1)
  168. {
  169. require_once(DEDEINC."/image.func.php");
  170. if(in_array($upfile_type, $cfg_photo_typenames))
  171. {
  172. WaterImg($fullfilename, 'up');
  173. }
  174. }
  175. $filesize = $upfile_size;
  176. $imgw = 0;
  177. $imgh = 0;
  178. if($mediatype==1)
  179. {
  180. $info = "";
  181. $sizes[0] = 0; $sizes[1] = 0;
  182. $sizes = @getimagesize($fullfilename, $info);
  183. $imgw = $sizes[0];
  184. $imgh = $sizes[1];
  185. }
  186. if($imgw>0)
  187. {
  188. $addquery = ",width='$imgw',height='$imgh',filesize='$filesize' ";
  189. }
  190. else
  191. {
  192. $addquery = ",filesize='$filesize' ";
  193. }
  194. }
  195. else
  196. {
  197. $fileurl = $filename;
  198. }
  199. //写入数据库
  200. $query = " UPDATE #@__uploads SET title='$title',mediatype='$mediatype',playtime='$playtime'";
  201. $query .= "$addquery WHERE aid='$aid' ";
  202. $dsql->ExecuteNoneQuery($query);
  203. ShowMsg('成功更改一则附件数据!','media_edit.php?aid='.$aid);
  204. exit();
  205. }
  206. //读取档案信息
  207. $myrow = $dsql->GetOne("SELECT * FROM #@__uploads WHERE aid='".$aid."'");
  208. if(!is_array($myrow))
  209. {
  210. ShowMsg('错误,找不到此编号的档案!','javascript:;');
  211. exit();
  212. }
  213. include DedeInclude('templets/media_edit.htm');