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

162 lines
5.8KB

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