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

167 lines
6.0KB

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