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

219 lines
6.6KB

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