connector.minimal.php-dist 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. error_reporting(0); // Set E_ALL for debuging
  3. // // Optional exec path settings (Default is called with command name only)
  4. // define('ELFINDER_TAR_PATH', '/PATH/TO/tar');
  5. // define('ELFINDER_GZIP_PATH', '/PATH/TO/gzip');
  6. // define('ELFINDER_BZIP2_PATH', '/PATH/TO/bzip2');
  7. // define('ELFINDER_XZ_PATH', '/PATH/TO/xz');
  8. // define('ELFINDER_ZIP_PATH', '/PATH/TO/zip');
  9. // define('ELFINDER_UNZIP_PATH', '/PATH/TO/unzip');
  10. // define('ELFINDER_RAR_PATH', '/PATH/TO/rar');
  11. // define('ELFINDER_UNRAR_PATH', '/PATH/TO/unrar');
  12. // define('ELFINDER_7Z_PATH', '/PATH/TO/7za');
  13. // define('ELFINDER_CONVERT_PATH', '/PATH/TO/convert');
  14. // define('ELFINDER_IDENTIFY_PATH', '/PATH/TO/identify');
  15. // define('ELFINDER_EXIFTRAN_PATH', '/PATH/TO/exiftran');
  16. // define('ELFINDER_JPEGTRAN_PATH', '/PATH/TO/jpegtran');
  17. // define('ELFINDER_FFMPEG_PATH', '/PATH/TO/ffmpeg');
  18. // define('ELFINDER_CONNECTOR_URL', 'URL to this connector script'); // see elFinder::getConnectorUrl()
  19. // define('ELFINDER_DEBUG_ERRORLEVEL', -1); // Error reporting level of debug mode
  20. // // To Enable(true) handling of PostScript files by ImageMagick
  21. // // It is disabled by default as a countermeasure
  22. // // of Ghostscript multiple -dSAFER sandbox bypass vulnerabilities
  23. // // see https://www.kb.cert.org/vuls/id/332928
  24. // define('ELFINDER_IMAGEMAGICK_PS', true);
  25. // ===============================================
  26. // // load composer autoload before load elFinder autoload If you need composer
  27. // // You need to run the composer command in the php directory.
  28. is_readable('./vendor/autoload.php') && require './vendor/autoload.php';
  29. // // elFinder autoload
  30. require './autoload.php';
  31. // ===============================================
  32. // // Enable FTP connector netmount
  33. elFinder::$netDrivers['ftp'] = 'FTP';
  34. // ===============================================
  35. // // Required for Dropbox network mount
  36. // // Installation by composer
  37. // // `composer require kunalvarma05/dropbox-php-sdk` on php directory
  38. // // Enable network mount
  39. // elFinder::$netDrivers['dropbox2'] = 'Dropbox2';
  40. // // Dropbox2 Netmount driver need next two settings. You can get at https://www.dropbox.com/developers/apps
  41. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=dropbox2&host=1"
  42. // // If the elFinder HTML element ID is not "elfinder", you need to change "host=1" to "host=ElementID"
  43. // define('ELFINDER_DROPBOX_APPKEY', '');
  44. // define('ELFINDER_DROPBOX_APPSECRET', '');
  45. // ===============================================
  46. // // Required for Google Drive network mount
  47. // // Installation by composer
  48. // // `composer require google/apiclient:^2.0` on php directory
  49. // // Enable network mount
  50. // elFinder::$netDrivers['googledrive'] = 'GoogleDrive';
  51. // // GoogleDrive Netmount driver need next two settings. You can get at https://console.developers.google.com
  52. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=googledrive&host=1"
  53. // // If the elFinder HTML element ID is not "elfinder", you need to change "host=1" to "host=ElementID"
  54. // define('ELFINDER_GOOGLEDRIVE_CLIENTID', '');
  55. // define('ELFINDER_GOOGLEDRIVE_CLIENTSECRET', '');
  56. // // Required case when Google API is NOT added via composer
  57. // define('ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT', '/path/to/google-api-php-client/vendor/autoload.php');
  58. // ===============================================
  59. // // Required for Google Drive network mount with Flysystem
  60. // // Installation by composer
  61. // // `composer require nao-pon/flysystem-google-drive:~1.1 nao-pon/elfinder-flysystem-driver-ext` on php directory
  62. // // Enable network mount
  63. // elFinder::$netDrivers['googledrive'] = 'FlysystemGoogleDriveNetmount';
  64. // // GoogleDrive Netmount driver need next two settings. You can get at https://console.developers.google.com
  65. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=googledrive&host=1"
  66. // // If the elFinder HTML element ID is not "elfinder", you need to change "host=1" to "host=ElementID"
  67. // define('ELFINDER_GOOGLEDRIVE_CLIENTID', '');
  68. // define('ELFINDER_GOOGLEDRIVE_CLIENTSECRET', '');
  69. // // And "php/.tmp" directory must exist and be writable by PHP.
  70. // ===============================================
  71. // // Required for One Drive network mount
  72. // // * cURL PHP extension required
  73. // // * HTTP server PATH_INFO supports required
  74. // // Enable network mount
  75. // elFinder::$netDrivers['onedrive'] = 'OneDrive';
  76. // // GoogleDrive Netmount driver need next two settings. You can get at https://dev.onedrive.com
  77. // // AND require register redirect url to "YOUR_CONNECTOR_URL/netmount/onedrive/1"
  78. // // If the elFinder HTML element ID is not "elfinder", you need to change "/1" to "/ElementID"
  79. // define('ELFINDER_ONEDRIVE_CLIENTID', '');
  80. // define('ELFINDER_ONEDRIVE_CLIENTSECRET', '');
  81. // ===============================================
  82. // // Required for Box network mount
  83. // // * cURL PHP extension required
  84. // // Enable network mount
  85. // elFinder::$netDrivers['box'] = 'Box';
  86. // // Box Netmount driver need next two settings. You can get at https://developer.box.com
  87. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=box&host=1"
  88. // // If the elFinder HTML element ID is not "elfinder", you need to change "host=1" to "host=ElementID"
  89. // define('ELFINDER_BOX_CLIENTID', '');
  90. // define('ELFINDER_BOX_CLIENTSECRET', '');
  91. // ===============================================
  92. // // Zoho Office Editor APIKey
  93. // // https://www.zoho.com/docs/help/office-apis.html
  94. // define('ELFINDER_ZOHO_OFFICE_APIKEY', '');
  95. // ===============================================
  96. // // Online converter (online-convert.com) APIKey
  97. // // https://apiv2.online-convert.com/docs/getting_started/api_key.html
  98. // define('ELFINDER_ONLINE_CONVERT_APIKEY', '');
  99. // ===============================================
  100. // // Zip Archive editor
  101. // // Installation by composer
  102. // // `composer require nao-pon/elfinder-flysystem-ziparchive-netmount` on php directory
  103. // define('ELFINDER_DISABLE_ZIPEDITOR', false); // set `true` to disable zip editor
  104. // ===============================================
  105. /**
  106. * Simple function to demonstrate how to control file access using "accessControl" callback.
  107. * This method will disable accessing files/folders starting from '.' (dot)
  108. *
  109. * @param string $attr attribute name (read|write|locked|hidden)
  110. * @param string $path absolute file path
  111. * @param string $data value of volume option `accessControlData`
  112. * @param object $volume elFinder volume driver object
  113. * @param bool|null $isDir path is directory (true: directory, false: file, null: unknown)
  114. * @param string $relpath file path relative to volume root directory started with directory separator
  115. * @return bool|null
  116. **/
  117. function access($attr, $path, $data, $volume, $isDir, $relpath) {
  118. $basename = basename($path);
  119. return $basename[0] === '.' // if file/folder begins with '.' (dot)
  120. && strlen($relpath) !== 1 // but with out volume root
  121. ? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
  122. : null; // else elFinder decide it itself
  123. }
  124. // Documentation for connector options:
  125. // https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
  126. $opts = array(
  127. // 'debug' => true,
  128. 'roots' => array(
  129. // Items volume
  130. array(
  131. 'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
  132. 'path' => '../files/', // path to files (REQUIRED)
  133. 'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
  134. 'trashHash' => 't1_Lw', // elFinder's hash of trash folder
  135. 'winHashFix' => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
  136. 'uploadDeny' => array('all'), // All Mimetypes not allowed to upload
  137. 'uploadAllow' => array('image/x-ms-bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/x-icon', 'text/plain'), // Mimetype `image` and `text/plain` allowed to upload
  138. 'uploadOrder' => array('deny', 'allow'), // allowed Mimetype `image` and `text/plain` only
  139. 'accessControl' => 'access' // disable and hide dot starting files (OPTIONAL)
  140. ),
  141. // Trash volume
  142. array(
  143. 'id' => '1',
  144. 'driver' => 'Trash',
  145. 'path' => '../files/.trash/',
  146. 'tmbURL' => dirname($_SERVER['PHP_SELF']) . '/../files/.trash/.tmb/',
  147. 'winHashFix' => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
  148. 'uploadDeny' => array('all'), // Recomend the same settings as the original volume that uses the trash
  149. 'uploadAllow' => array('image/x-ms-bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/x-icon', 'text/plain'), // Same as above
  150. 'uploadOrder' => array('deny', 'allow'), // Same as above
  151. 'accessControl' => 'access', // Same as above
  152. ),
  153. )
  154. );
  155. // run elFinder
  156. $connector = new elFinderConnector(new elFinder($opts));
  157. $connector->run();