Elfinder.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Config;
  5. use think\console\Input;
  6. use think\Db;
  7. use think\Exception;
  8. use think\Loader;
  9. /**
  10. * 在线命令管理
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class Elfinder extends Backend
  15. {
  16. protected $noNeedRight = ['view'];
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. if (!config("app_debug")) {
  21. $this->error("只允许在开发环境下使用");
  22. }
  23. include_once ADDON_PATH . 'elfinder' . DS . 'library' . DS . 'elfinder' . DS . 'autoload.php';
  24. }
  25. public function index()
  26. {
  27. return $this->view->fetch();
  28. }
  29. public function view()
  30. {
  31. $config = get_addon_config('elfinder');
  32. $allowType = explode(',', $config['allow_upload']);
  33. $allNeedTypes = [];
  34. foreach ($allowType as $key => $type) {
  35. if (isset(self::$mimetypes[$type])) {
  36. $allNeedTypes[] = self::$mimetypes[$type];
  37. } else {
  38. $allNeedTypes[] = $type;
  39. }
  40. }
  41. $allWrite = explode(',', $config['allow_write']);
  42. $accessControl = 'roaccess';
  43. if (in_array($this->auth->id, $allWrite)) {
  44. $accessControl = 'rwaccess';
  45. }
  46. $allNeedTypes = array_values(array_unique($allNeedTypes));
  47. $opts = array(
  48. // 'debug' => true,
  49. 'roots' => array(
  50. // Items volume
  51. array(
  52. 'driver' => $config['driver'], // driver for accessing file system (REQUIRED)
  53. 'path' => $config['path'], // path to files (REQUIRED)
  54. 'URL' => $config['url'], // URL to files (REQUIRED)
  55. // 'trashHash' => 't1_Lw', // elFinder's hash of trash folder
  56. 'winHashFix' => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
  57. 'uploadDeny' => ['all'], // All Mimetypes not allowed to upload
  58. 'uploadAllow' => $allNeedTypes,// Mimetype `image` and `text/plain` allowed to upload
  59. 'uploadOrder' => array('deny', 'allow'), // allowed Mimetype `image` and `text/plain` only
  60. 'accessControl' => $accessControl // disable and hide dot starting files (OPTIONAL)
  61. )
  62. )
  63. );
  64. $connector = new \elFinderConnector(new \elFinder($opts));
  65. $connector->run();
  66. }
  67. /**
  68. * default extensions/mimetypes for mimeDetect == 'internal'
  69. * 这个是Elfinder格式校验对应关系
  70. * @var array
  71. **/
  72. protected static $mimetypes = array(
  73. // applications
  74. 'ai' => 'application/postscript',
  75. 'eps' => 'application/postscript',
  76. 'exe' => 'application/x-executable',
  77. 'doc' => 'application/msword',
  78. 'dot' => 'application/msword',
  79. 'xls' => 'application/vnd.ms-excel',
  80. 'xlt' => 'application/vnd.ms-excel',
  81. 'xla' => 'application/vnd.ms-excel',
  82. 'ppt' => 'application/vnd.ms-powerpoint',
  83. 'pps' => 'application/vnd.ms-powerpoint',
  84. 'pdf' => 'application/pdf',
  85. 'xml' => 'application/xml',
  86. 'swf' => 'application/x-shockwave-flash',
  87. 'torrent' => 'application/x-bittorrent',
  88. 'jar' => 'application/x-jar',
  89. // open office (finfo detect as application/zip)
  90. 'odt' => 'application/vnd.oasis.opendocument.text',
  91. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  92. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  93. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  94. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  95. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  96. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  97. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  98. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  99. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  100. 'odc' => 'application/vnd.oasis.opendocument.chart',
  101. 'odf' => 'application/vnd.oasis.opendocument.formula',
  102. 'odb' => 'application/vnd.oasis.opendocument.database',
  103. 'odi' => 'application/vnd.oasis.opendocument.image',
  104. 'oxt' => 'application/vnd.openofficeorg.extension',
  105. // MS office 2007 (finfo detect as application/zip)
  106. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  107. 'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
  108. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  109. 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
  110. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  111. 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
  112. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  113. 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
  114. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  115. 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
  116. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  117. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
  118. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  119. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
  120. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  121. 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
  122. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
  123. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  124. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
  125. // archives
  126. 'gz' => 'application/x-gzip',
  127. 'tgz' => 'application/x-gzip',
  128. 'bz' => 'application/x-bzip2',
  129. 'bz2' => 'application/x-bzip2',
  130. 'tbz' => 'application/x-bzip2',
  131. 'xz' => 'application/x-xz',
  132. 'zip' => 'application/zip',
  133. 'rar' => 'application/x-rar',
  134. 'tar' => 'application/x-tar',
  135. '7z' => 'application/x-7z-compressed',
  136. // texts
  137. 'txt' => 'text/plain',
  138. 'php' => 'text/x-php',
  139. 'html' => 'text/html',
  140. 'htm' => 'text/html',
  141. 'js' => 'application/javascript',
  142. 'css' => 'text/css',
  143. 'rtf' => 'text/rtf',
  144. 'rtfd' => 'text/rtfd',
  145. 'py' => 'text/x-python',
  146. 'java' => 'text/x-java-source',
  147. 'rb' => 'text/x-ruby',
  148. 'sh' => 'text/x-shellscript',
  149. 'pl' => 'text/x-perl',
  150. 'xml' => 'text/xml',
  151. 'sql' => 'text/x-sql',
  152. 'c' => 'text/x-csrc',
  153. 'h' => 'text/x-chdr',
  154. 'cpp' => 'text/x-c++src',
  155. 'hh' => 'text/x-c++hdr',
  156. 'log' => 'text/plain',
  157. 'csv' => 'text/csv',
  158. 'md' => 'text/x-markdown',
  159. 'markdown' => 'text/x-markdown',
  160. // images
  161. 'bmp' => 'image/x-ms-bmp',
  162. 'jpg' => 'image/jpeg',
  163. 'jpeg' => 'image/jpeg',
  164. 'gif' => 'image/gif',
  165. 'png' => 'image/png',
  166. 'tif' => 'image/tiff',
  167. 'tiff' => 'image/tiff',
  168. 'tga' => 'image/x-targa',
  169. 'psd' => 'image/vnd.adobe.photoshop',
  170. //'ai' => 'image/vnd.adobe.photoshop',
  171. 'xbm' => 'image/xbm',
  172. 'pxm' => 'image/pxm',
  173. //audio
  174. 'mp3' => 'audio/mpeg',
  175. 'mid' => 'audio/midi',
  176. 'ogg' => 'audio/ogg',
  177. 'oga' => 'audio/ogg',
  178. 'm4a' => 'audio/mp4',
  179. 'wav' => 'audio/wav',
  180. 'wma' => 'audio/x-ms-wma',
  181. // video
  182. 'avi' => 'video/x-msvideo',
  183. 'dv' => 'video/x-dv',
  184. 'mp4' => 'video/mp4',
  185. 'mpeg' => 'video/mpeg',
  186. 'mpg' => 'video/mpeg',
  187. 'mov' => 'video/quicktime',
  188. 'wm' => 'video/x-ms-wmv',
  189. 'flv' => 'video/x-flv',
  190. 'mkv' => 'video/x-matroska',
  191. 'webm' => 'video/webm',
  192. 'ogv' => 'video/ogg',
  193. 'ogm' => 'video/ogg',
  194. 'm2ts' => 'video/MP2T',
  195. 'mts' => 'video/MP2T',
  196. 'ts' => 'video/MP2T',
  197. 'm3u8' => 'application/x-mpegURL',
  198. 'mpd' => 'application/dash+xml'
  199. );
  200. }