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

180 lines
6.4KB

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