PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_k2/lib/elfinder/elFinderVolumeDriver.class.php

https://github.com/J2MTecnologia/joomla-3.x
PHP | 3381 lines | 1698 code | 474 blank | 1209 comment | 564 complexity | 805afc012d777876cdd34f0e3fe80747 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @version $Id: elFinderVolumeDriver.class.php 1989 2013-07-04 13:52:28Z lefteris.kavadas $
  4. * @package K2
  5. * @author JoomlaWorks http://www.joomlaworks.net
  6. * @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
  7. * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
  8. */
  9. // no direct access
  10. defined('_JEXEC') or die;
  11. /**
  12. * Base class for elFinder volume.
  13. * Provide 2 layers:
  14. * 1. Public API (commands)
  15. * 2. abstract fs API
  16. *
  17. * All abstract methods begin with "_"
  18. *
  19. * @author Dmitry (dio) Levashov
  20. * @author Troex Nevelin
  21. * @author Alexey Sukhotin
  22. **/
  23. abstract class elFinderVolumeDriver {
  24. /**
  25. * Driver id
  26. * Must be started from letter and contains [a-z0-9]
  27. * Used as part of volume id
  28. *
  29. * @var string
  30. **/
  31. protected $driverId = 'a';
  32. /**
  33. * Volume id - used as prefix for files hashes
  34. *
  35. * @var string
  36. **/
  37. protected $id = '';
  38. /**
  39. * Flag - volume "mounted" and available
  40. *
  41. * @var bool
  42. **/
  43. protected $mounted = false;
  44. /**
  45. * Root directory path
  46. *
  47. * @var string
  48. **/
  49. protected $root = '';
  50. /**
  51. * Root basename | alias
  52. *
  53. * @var string
  54. **/
  55. protected $rootName = '';
  56. /**
  57. * Default directory to open
  58. *
  59. * @var string
  60. **/
  61. protected $startPath = '';
  62. /**
  63. * Base URL
  64. *
  65. * @var string
  66. **/
  67. protected $URL = '';
  68. /**
  69. * Thumbnails dir path
  70. *
  71. * @var string
  72. **/
  73. protected $tmbPath = '';
  74. /**
  75. * Is thumbnails dir writable
  76. *
  77. * @var bool
  78. **/
  79. protected $tmbPathWritable = false;
  80. /**
  81. * Thumbnails base URL
  82. *
  83. * @var string
  84. **/
  85. protected $tmbURL = '';
  86. /**
  87. * Thumbnails size in px
  88. *
  89. * @var int
  90. **/
  91. protected $tmbSize = 48;
  92. /**
  93. * Image manipulation lib name
  94. * auto|imagick|mogtify|gd
  95. *
  96. * @var string
  97. **/
  98. protected $imgLib = 'auto';
  99. /**
  100. * Library to crypt files name
  101. *
  102. * @var string
  103. **/
  104. protected $cryptLib = '';
  105. /**
  106. * Archivers config
  107. *
  108. * @var array
  109. **/
  110. protected $archivers = array(
  111. 'create' => array(),
  112. 'extract' => array()
  113. );
  114. /**
  115. * How many subdirs levels return for tree
  116. *
  117. * @var int
  118. **/
  119. protected $treeDeep = 1;
  120. /**
  121. * Errors from last failed action
  122. *
  123. * @var array
  124. **/
  125. protected $error = array();
  126. /**
  127. * Today 24:00 timestamp
  128. *
  129. * @var int
  130. **/
  131. protected $today = 0;
  132. /**
  133. * Yesterday 24:00 timestamp
  134. *
  135. * @var int
  136. **/
  137. protected $yesterday = 0;
  138. /**
  139. * Object configuration
  140. *
  141. * @var array
  142. **/
  143. protected $options = array(
  144. 'id' => '',
  145. // root directory path
  146. 'path' => '',
  147. // open this path on initial request instead of root path
  148. 'startPath' => '',
  149. // how many subdirs levels return per request
  150. 'treeDeep' => 1,
  151. // root url, not set to disable sending URL to client (replacement for old "fileURL" option)
  152. 'URL' => '',
  153. // directory separator. required by client to show paths correctly
  154. 'separator' => DIRECTORY_SEPARATOR,
  155. // library to crypt/uncrypt files names (not implemented)
  156. 'cryptLib' => '',
  157. // how to detect files mimetypes. (auto/internal/finfo/mime_content_type)
  158. 'mimeDetect' => 'auto',
  159. // mime.types file path (for mimeDetect==internal)
  160. 'mimefile' => '',
  161. // directory for thumbnails
  162. 'tmbPath' => '.tmb',
  163. // mode to create thumbnails dir
  164. 'tmbPathMode' => 0755,
  165. // thumbnails dir URL. Set it if store thumbnails outside root directory
  166. 'tmbURL' => '',
  167. // thumbnails size (px)
  168. 'tmbSize' => 48,
  169. // thumbnails crop (true - crop, false - scale image to fit thumbnail size)
  170. 'tmbCrop' => true,
  171. // thumbnails background color (hex #rrggbb or 'transparent')
  172. 'tmbBgColor' => '#ffffff',
  173. // image manipulations library
  174. 'imgLib' => 'auto',
  175. // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext
  176. 'copyOverwrite' => true,
  177. // if true - join new and old directories content on paste
  178. 'copyJoin' => true,
  179. // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext
  180. 'uploadOverwrite' => true,
  181. // mimetypes allowed to upload
  182. 'uploadAllow' => array(),
  183. // mimetypes not allowed to upload
  184. 'uploadDeny' => array(),
  185. // order to proccess uploadAllow and uploadDeny options
  186. 'uploadOrder' => array('deny', 'allow'),
  187. // maximum upload file size. NOTE - this is size for every uploaded files
  188. 'uploadMaxSize' => 0,
  189. // files dates format
  190. 'dateFormat' => 'j M Y H:i',
  191. // files time format
  192. 'timeFormat' => 'H:i',
  193. // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders
  194. 'checkSubfolders' => true,
  195. // allow to copy from this volume to other ones?
  196. 'copyFrom' => true,
  197. // allow to copy from other volumes to this one?
  198. 'copyTo' => true,
  199. // list of commands disabled on this root
  200. 'disabled' => array(),
  201. // regexp or function name to validate new file name
  202. 'acceptedName' => '/^\w[\w\s\.\%\-\(\)\[\]]*$/u',
  203. // function/class method to control files permissions
  204. 'accessControl' => null,
  205. // some data required by access control
  206. 'accessControlData' => null,
  207. // default permissions. not set hidden/locked here - take no effect
  208. 'defaults' => array(
  209. 'read' => true,
  210. 'write' => true
  211. ),
  212. // files attributes
  213. 'attributes' => array(),
  214. // Allowed archive's mimetypes to create. Leave empty for all available types.
  215. 'archiveMimes' => array(),
  216. // Manual config for archivers. See example below. Leave empty for auto detect
  217. 'archivers' => array(),
  218. // required to fix bug on macos
  219. 'utf8fix' => false,
  220. // й ё Й Ё Ø Å
  221. 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"),
  222. 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5")
  223. );
  224. /**
  225. * Defaults permissions
  226. *
  227. * @var array
  228. **/
  229. protected $defaults = array(
  230. 'read' => true,
  231. 'write' => true,
  232. 'locked' => false,
  233. 'hidden' => false
  234. );
  235. /**
  236. * Access control function/class
  237. *
  238. * @var mixed
  239. **/
  240. protected $attributes = array();
  241. /**
  242. * Access control function/class
  243. *
  244. * @var mixed
  245. **/
  246. protected $access = null;
  247. /**
  248. * Mime types allowed to upload
  249. *
  250. * @var array
  251. **/
  252. protected $uploadAllow = array();
  253. /**
  254. * Mime types denied to upload
  255. *
  256. * @var array
  257. **/
  258. protected $uploadDeny = array();
  259. /**
  260. * Order to validate uploadAllow and uploadDeny
  261. *
  262. * @var array
  263. **/
  264. protected $uploadOrder = array();
  265. /**
  266. * Maximum allowed upload file size.
  267. * Set as number or string with unit - "10M", "500K", "1G"
  268. *
  269. * @var int|string
  270. **/
  271. protected $uploadMaxSize = 0;
  272. /**
  273. * Mimetype detect method
  274. *
  275. * @var string
  276. **/
  277. protected $mimeDetect = 'auto';
  278. /**
  279. * Flag - mimetypes from externail file was loaded
  280. *
  281. * @var bool
  282. **/
  283. private static $mimetypesLoaded = false;
  284. /**
  285. * Finfo object for mimeDetect == 'finfo'
  286. *
  287. * @var object
  288. **/
  289. protected $finfo = null;
  290. /**
  291. * List of disabled client's commands
  292. *
  293. * @var array
  294. **/
  295. protected $diabled = array();
  296. /**
  297. * default extensions/mimetypes for mimeDetect == 'internal'
  298. *
  299. * @var array
  300. **/
  301. protected static $mimetypes = array(
  302. // applications
  303. 'ai' => 'application/postscript',
  304. 'eps' => 'application/postscript',
  305. 'exe' => 'application/x-executable',
  306. 'doc' => 'application/vnd.ms-word',
  307. 'xls' => 'application/vnd.ms-excel',
  308. 'ppt' => 'application/vnd.ms-powerpoint',
  309. 'pps' => 'application/vnd.ms-powerpoint',
  310. 'pdf' => 'application/pdf',
  311. 'xml' => 'application/xml',
  312. 'odt' => 'application/vnd.oasis.opendocument.text',
  313. 'swf' => 'application/x-shockwave-flash',
  314. 'torrent' => 'application/x-bittorrent',
  315. 'jar' => 'application/x-jar',
  316. // archives
  317. 'gz' => 'application/x-gzip',
  318. 'tgz' => 'application/x-gzip',
  319. 'bz' => 'application/x-bzip2',
  320. 'bz2' => 'application/x-bzip2',
  321. 'tbz' => 'application/x-bzip2',
  322. 'zip' => 'application/zip',
  323. 'rar' => 'application/x-rar',
  324. 'tar' => 'application/x-tar',
  325. '7z' => 'application/x-7z-compressed',
  326. // texts
  327. 'txt' => 'text/plain',
  328. 'php' => 'text/x-php',
  329. 'html' => 'text/html',
  330. 'htm' => 'text/html',
  331. 'js' => 'text/javascript',
  332. 'css' => 'text/css',
  333. 'rtf' => 'text/rtf',
  334. 'rtfd' => 'text/rtfd',
  335. 'py' => 'text/x-python',
  336. 'java' => 'text/x-java-source',
  337. 'rb' => 'text/x-ruby',
  338. 'sh' => 'text/x-shellscript',
  339. 'pl' => 'text/x-perl',
  340. 'xml' => 'text/xml',
  341. 'sql' => 'text/x-sql',
  342. 'c' => 'text/x-csrc',
  343. 'h' => 'text/x-chdr',
  344. 'cpp' => 'text/x-c++src',
  345. 'hh' => 'text/x-c++hdr',
  346. 'log' => 'text/plain',
  347. 'csv' => 'text/x-comma-separated-values',
  348. // images
  349. 'bmp' => 'image/x-ms-bmp',
  350. 'jpg' => 'image/jpeg',
  351. 'jpeg' => 'image/jpeg',
  352. 'gif' => 'image/gif',
  353. 'png' => 'image/png',
  354. 'tif' => 'image/tiff',
  355. 'tiff' => 'image/tiff',
  356. 'tga' => 'image/x-targa',
  357. 'psd' => 'image/vnd.adobe.photoshop',
  358. 'ai' => 'image/vnd.adobe.photoshop',
  359. 'xbm' => 'image/xbm',
  360. 'pxm' => 'image/pxm',
  361. //audio
  362. 'mp3' => 'audio/mpeg',
  363. 'mid' => 'audio/midi',
  364. 'ogg' => 'audio/ogg',
  365. 'oga' => 'audio/ogg',
  366. 'm4a' => 'audio/x-m4a',
  367. 'wav' => 'audio/wav',
  368. 'wma' => 'audio/x-ms-wma',
  369. // video
  370. 'avi' => 'video/x-msvideo',
  371. 'dv' => 'video/x-dv',
  372. 'mp4' => 'video/mp4',
  373. 'mpeg' => 'video/mpeg',
  374. 'mpg' => 'video/mpeg',
  375. 'mov' => 'video/quicktime',
  376. 'wm' => 'video/x-ms-wmv',
  377. 'flv' => 'video/x-flv',
  378. 'mkv' => 'video/x-matroska',
  379. 'webm' => 'video/webm',
  380. 'ogv' => 'video/ogg',
  381. 'ogm' => 'video/ogg'
  382. );
  383. /**
  384. * Directory separator - required by client
  385. *
  386. * @var string
  387. **/
  388. protected $separator = DIRECTORY_SEPARATOR;
  389. /**
  390. * Mimetypes allowed to display
  391. *
  392. * @var array
  393. **/
  394. protected $onlyMimes = array();
  395. /**
  396. * Store files moved or overwrited files info
  397. *
  398. * @var array
  399. **/
  400. protected $removed = array();
  401. /**
  402. * Cache storage
  403. *
  404. * @var array
  405. **/
  406. protected $cache = array();
  407. /**
  408. * Cache by folders
  409. *
  410. * @var array
  411. **/
  412. protected $dirsCache = array();
  413. /*********************************************************************/
  414. /* INITIALIZATION */
  415. /*********************************************************************/
  416. /**
  417. * Prepare driver before mount volume.
  418. * Return true if volume is ready.
  419. *
  420. * @return bool
  421. * @author Dmitry (dio) Levashov
  422. **/
  423. protected function init() {
  424. return true;
  425. }
  426. /**
  427. * Configure after successfull mount.
  428. * By default set thumbnails path and image manipulation library.
  429. *
  430. * @return void
  431. * @author Dmitry (dio) Levashov
  432. **/
  433. protected function configure() {
  434. // set thumbnails path
  435. $path = $this->options['tmbPath'];
  436. if ($path) {
  437. if (!file_exists($path)) {
  438. if (@mkdir($path)) {
  439. chmod($path, $this->options['tmbPathMode']);
  440. } else {
  441. $path = '';
  442. }
  443. }
  444. if (is_dir($path) && is_readable($path)) {
  445. $this->tmbPath = $path;
  446. $this->tmbPathWritable = is_writable($path);
  447. }
  448. }
  449. // set image manipulation library
  450. $type = preg_match('/^(imagick|gd|auto)$/i', $this->options['imgLib'])
  451. ? strtolower($this->options['imgLib'])
  452. : 'auto';
  453. if (($type == 'imagick' || $type == 'auto') && extension_loaded('imagick')) {
  454. $this->imgLib = 'imagick';
  455. } else {
  456. $this->imgLib = function_exists('gd_info') ? 'gd' : '';
  457. }
  458. }
  459. /*********************************************************************/
  460. /* PUBLIC API */
  461. /*********************************************************************/
  462. /**
  463. * Return driver id. Used as a part of volume id.
  464. *
  465. * @return string
  466. * @author Dmitry (dio) Levashov
  467. **/
  468. public function driverId() {
  469. return $this->driverId;
  470. }
  471. /**
  472. * Return volume id
  473. *
  474. * @return string
  475. * @author Dmitry (dio) Levashov
  476. **/
  477. public function id() {
  478. return $this->id;
  479. }
  480. /**
  481. * Return debug info for client
  482. *
  483. * @return array
  484. * @author Dmitry (dio) Levashov
  485. **/
  486. public function debug() {
  487. return array(
  488. 'id' => $this->id(),
  489. 'name' => strtolower(substr(get_class($this), strlen('elfinderdriver'))),
  490. 'mimeDetect' => $this->mimeDetect,
  491. 'imgLib' => $this->imgLib
  492. );
  493. }
  494. /**
  495. * "Mount" volume.
  496. * Return true if volume available for read or write,
  497. * false - otherwise
  498. *
  499. * @return bool
  500. * @author Dmitry (dio) Levashov
  501. * @author Alexey Sukhotin
  502. **/
  503. public function mount(array $opts) {
  504. if (!isset($opts['path']) || $opts['path'] === '') {
  505. return false;
  506. }
  507. $this->options = array_merge($this->options, $opts);
  508. $this->id = $this->driverId.(!empty($this->options['id']) ? $this->options['id'] : elFinder::$volumesCnt++).'_';
  509. $this->root = $this->_normpath($this->options['path']);
  510. $this->separator = isset($this->options['separator']) ? $this->options['separator'] : DIRECTORY_SEPARATOR;
  511. // default file attribute
  512. $this->defaults = array(
  513. 'read' => isset($this->options['defaults']['read']) ? !!$this->options['defaults']['read'] : true,
  514. 'write' => isset($this->options['defaults']['write']) ? !!$this->options['defaults']['write'] : true,
  515. 'locked' => false,
  516. 'hidden' => false
  517. );
  518. // root attributes
  519. $this->attributes[] = array(
  520. 'pattern' => '~^'.preg_quote(DIRECTORY_SEPARATOR).'$~',
  521. 'locked' => true,
  522. 'hidden' => false
  523. );
  524. // set files attributes
  525. if (!empty($this->options['attributes']) && is_array($this->options['attributes'])) {
  526. foreach ($this->options['attributes'] as $a) {
  527. // attributes must contain pattern and at least one rule
  528. if (!empty($a['pattern']) || count($a) > 1) {
  529. $this->attributes[] = $a;
  530. }
  531. }
  532. }
  533. if (!empty($this->options['accessControl'])) {
  534. if (is_string($this->options['accessControl'])
  535. && function_exists($this->options['accessControl'])) {
  536. $this->access = $this->options['accessControl'];
  537. } elseif (is_array($this->options['accessControl'])
  538. && count($this->options['accessControl']) > 1
  539. && is_object($this->options['accessControl'][0])
  540. && method_exists($this->options['accessControl'][0], $this->options['accessControl'][1])) {
  541. $this->access = array($this->options['accessControl'][0], $this->options['accessControl'][1]);
  542. }
  543. }
  544. $this->today = mktime(0,0,0, date('m'), date('d'), date('Y'));
  545. $this->yesterday = $this->today-86400;
  546. // debug($this->attributes);
  547. if (!$this->init()) {
  548. return false;
  549. }
  550. // check some options is arrays
  551. $this->uploadAllow = isset($this->options['uploadAllow']) && is_array($this->options['uploadAllow'])
  552. ? $this->options['uploadAllow']
  553. : array();
  554. $this->uploadDeny = isset($this->options['uploadDeny']) && is_array($this->options['uploadDeny'])
  555. ? $this->options['uploadDeny']
  556. : array();
  557. if (is_string($this->options['uploadOrder'])) { // telephat_mode on, compatibility with 1.x
  558. $parts = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow');
  559. $this->uploadOrder = array(trim($parts[0]), trim($parts[1]));
  560. } else { // telephat_mode off
  561. $this->uploadOrder = $this->options['uploadOrder'];
  562. }
  563. if (!empty($this->options['uploadMaxSize'])) {
  564. $size = ''.$this->options['uploadMaxSize'];
  565. $unit = strtolower(substr($size, strlen($size) - 1));
  566. $n = 1;
  567. switch ($unit) {
  568. case 'k':
  569. $n = 1024;
  570. break;
  571. case 'm':
  572. $n = 1048576;
  573. break;
  574. case 'g':
  575. $n = 1073741824;
  576. }
  577. $this->uploadMaxSize = intval($size)*$n;
  578. }
  579. $this->disabled = isset($this->options['disabled']) && is_array($this->options['disabled'])
  580. ? $this->options['disabled']
  581. : array();
  582. $this->cryptLib = $this->options['cryptLib'];
  583. $this->mimeDetect = $this->options['mimeDetect'];
  584. // find available mimetype detect method
  585. $type = strtolower($this->options['mimeDetect']);
  586. $type = preg_match('/^(finfo|mime_content_type|internal|auto)$/i', $type) ? $type : 'auto';
  587. $regexp = '/text\/x\-(php|c\+\+)/';
  588. if (($type == 'finfo' || $type == 'auto')
  589. && class_exists('finfo')
  590. && @preg_match($regexp, array_shift(explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__))))) {
  591. $type = 'finfo';
  592. $this->finfo = finfo_open(FILEINFO_MIME);
  593. } elseif (($type == 'mime_content_type' || $type == 'auto')
  594. && function_exists('mime_content_type')
  595. && preg_match($regexp, array_shift(explode(';', mime_content_type(__FILE__))))) {
  596. $type = 'mime_content_type';
  597. } else {
  598. $type = 'internal';
  599. }
  600. $this->mimeDetect = $type;
  601. // load mimes from external file for mimeDetect == 'internal'
  602. // based on Alexey Sukhotin idea and patch: http://elrte.org/redmine/issues/163
  603. // file must be in file directory or in parent one
  604. if ($this->mimeDetect == 'internal' && !self::$mimetypesLoaded) {
  605. self::$mimetypesLoaded = true;
  606. $this->mimeDetect = 'internal';
  607. $file = false;
  608. if (!empty($this->options['mimefile']) && file_exists($this->options['mimefile'])) {
  609. $file = $this->options['mimefile'];
  610. } elseif (file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types')) {
  611. $file = dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types';
  612. } elseif (file_exists(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types')) {
  613. $file = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types';
  614. }
  615. if ($file && file_exists($file)) {
  616. $mimecf = file($file);
  617. foreach ($mimecf as $line_num => $line) {
  618. if (!preg_match('/^\s*#/', $line)) {
  619. $mime = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
  620. for ($i = 1, $size = count($mime); $i < $size ; $i++) {
  621. if (!isset(self::$mimetypes[$mime[$i]])) {
  622. self::$mimetypes[$mime[$i]] = $mime[0];
  623. }
  624. }
  625. }
  626. }
  627. }
  628. }
  629. $this->rootName = empty($this->options['alias']) ? $this->_basename($this->root) : $this->options['alias'];
  630. $root = $this->stat($this->root);
  631. if (!$root) {
  632. return $this->setError('Root folder does not exists.');
  633. }
  634. if (!$root['read'] && !$root['write']) {
  635. return $this->setError('Root folder has not read and write permissions.');
  636. }
  637. // debug($root);
  638. if ($root['read']) {
  639. // check startPath - path to open by default instead of root
  640. if ($this->options['startPath']) {
  641. $start = $this->stat($this->options['startPath']);
  642. if (!empty($start)
  643. && $start['mime'] == 'directory'
  644. && $start['read']
  645. && empty($start['hidden'])
  646. && $this->_inpath($this->options['startPath'], $this->root)) {
  647. $this->startPath = $this->options['startPath'];
  648. if (substr($this->startPath, -1, 1) == $this->options['separator']) {
  649. $this->startPath = substr($this->startPath, 0, -1);
  650. }
  651. }
  652. }
  653. } else {
  654. $this->options['URL'] = '';
  655. $this->options['tmbURL'] = '';
  656. $this->options['tmbPath'] = '';
  657. // read only volume
  658. array_unshift($this->attributes, array(
  659. 'pattern' => '/.*/',
  660. 'read' => false
  661. ));
  662. }
  663. $this->treeDeep = $this->options['treeDeep'] > 0 ? (int)$this->options['treeDeep'] : 1;
  664. $this->tmbSize = $this->options['tmbSize'] > 0 ? (int)$this->options['tmbSize'] : 48;
  665. $this->URL = $this->options['URL'];
  666. if ($this->URL && preg_match("|[^/?&=]$|", $this->URL)) {
  667. $this->URL .= '/';
  668. }
  669. $this->tmbURL = !empty($this->options['tmbURL']) ? $this->options['tmbURL'] : '';
  670. if ($this->tmbURL && preg_match("|[^/?&=]$|", $this->tmbURL)) {
  671. $this->tmbURL .= '/';
  672. }
  673. $this->nameValidator = is_string($this->options['acceptedName']) && !empty($this->options['acceptedName'])
  674. ? $this->options['acceptedName']
  675. : '';
  676. $this->_checkArchivers();
  677. // manual control archive types to create
  678. if (!empty($this->options['archiveMimes']) && is_array($this->options['archiveMimes'])) {
  679. foreach ($this->archivers['create'] as $mime => $v) {
  680. if (!in_array($mime, $this->options['archiveMimes'])) {
  681. unset($this->archivers['create'][$mime]);
  682. }
  683. }
  684. }
  685. // manualy add archivers
  686. if (!empty($this->options['archivers']['create']) && is_array($this->options['archivers']['create'])) {
  687. foreach ($this->options['archivers']['create'] as $mime => $conf) {
  688. if (strpos($mime, 'application/') === 0
  689. && !empty($conf['cmd'])
  690. && isset($conf['argc'])
  691. && !empty($conf['ext'])
  692. && !isset($this->archivers['create'][$mime])) {
  693. $this->archivers['create'][$mime] = $conf;
  694. }
  695. }
  696. }
  697. if (!empty($this->options['archivers']['extract']) && is_array($this->options['archivers']['extract'])) {
  698. foreach ($this->options['archivers']['extract'] as $mime => $conf) {
  699. if (substr($mime, 'application/') === 0
  700. && !empty($cons['cmd'])
  701. && isset($conf['argc'])
  702. && !empty($conf['ext'])
  703. && !isset($this->archivers['extract'][$mime])) {
  704. $this->archivers['extract'][$mime] = $conf;
  705. }
  706. }
  707. }
  708. $this->configure();
  709. // echo $this->uploadMaxSize;
  710. // echo $this->options['uploadMaxSize'];
  711. return $this->mounted = true;
  712. }
  713. /**
  714. * Some "unmount" stuffs - may be required by virtual fs
  715. *
  716. * @return void
  717. * @author Dmitry (dio) Levashov
  718. **/
  719. public function umount() {
  720. }
  721. /**
  722. * Return error message from last failed action
  723. *
  724. * @return array
  725. * @author Dmitry (dio) Levashov
  726. **/
  727. public function error() {
  728. return $this->error;
  729. }
  730. /**
  731. * Set mimetypes allowed to display to client
  732. *
  733. * @param array $mimes
  734. * @return void
  735. * @author Dmitry (dio) Levashov
  736. **/
  737. public function setMimesFilter($mimes) {
  738. if (is_array($mimes)) {
  739. $this->onlyMimes = $mimes;
  740. }
  741. }
  742. /**
  743. * Return root folder hash
  744. *
  745. * @return string
  746. * @author Dmitry (dio) Levashov
  747. **/
  748. public function root() {
  749. return $this->encode($this->root);
  750. }
  751. /**
  752. * Return root or startPath hash
  753. *
  754. * @return string
  755. * @author Dmitry (dio) Levashov
  756. **/
  757. public function defaultPath() {
  758. return $this->encode($this->startPath ? $this->startPath : $this->root);
  759. }
  760. /**
  761. * Return volume options required by client:
  762. *
  763. * @return array
  764. * @author Dmitry (dio) Levashov
  765. **/
  766. public function options($hash) {
  767. return array(
  768. 'path' => $this->_path($this->decode($hash)),
  769. 'url' => $this->URL,
  770. 'tmbUrl' => $this->tmbURL,
  771. 'disabled' => $this->disabled,
  772. 'separator' => $this->separator,
  773. 'copyOverwrite' => intval($this->options['copyOverwrite']),
  774. 'archivers' => array(
  775. 'create' => array_keys($this->archivers['create']),
  776. 'extract' => array_keys($this->archivers['extract'])
  777. )
  778. );
  779. }
  780. /**
  781. * Return true if command disabled in options
  782. *
  783. * @param string $cmd command name
  784. * @return bool
  785. * @author Dmitry (dio) Levashov
  786. **/
  787. public function commandDisabled($cmd) {
  788. return in_array($cmd, $this->disabled);
  789. }
  790. /**
  791. * Return true if mime is required mimes list
  792. *
  793. * @param string $mime mime type to check
  794. * @param array $mimes allowed mime types list or not set to use client mimes list
  795. * @param bool|null $empty what to return on empty list
  796. * @return bool|null
  797. * @author Dmitry (dio) Levashov
  798. * @author Troex Nevelin
  799. **/
  800. public function mimeAccepted($mime, $mimes = array(), $empty = true) {
  801. $mimes = !empty($mimes) ? $mimes : $this->onlyMimes;
  802. if (empty($mimes)) {
  803. return $empty;
  804. }
  805. return $mime == 'directory'
  806. || in_array('all', $mimes)
  807. || in_array('All', $mimes)
  808. || in_array($mime, $mimes)
  809. || in_array(substr($mime, 0, strpos($mime, '/')), $mimes);
  810. }
  811. /**
  812. * Return true if voume is readable.
  813. *
  814. * @return bool
  815. * @author Dmitry (dio) Levashov
  816. **/
  817. public function isReadable() {
  818. $stat = $this->stat($this->root);
  819. return $stat['read'];
  820. }
  821. /**
  822. * Return true if copy from this volume allowed
  823. *
  824. * @return bool
  825. * @author Dmitry (dio) Levashov
  826. **/
  827. public function copyFromAllowed() {
  828. return !!$this->options['copyFrom'];
  829. }
  830. /**
  831. * Return file path related to root
  832. *
  833. * @param string $hash file hash
  834. * @return string
  835. * @author Dmitry (dio) Levashov
  836. **/
  837. public function path($hash) {
  838. return $this->_path($this->decode($hash));
  839. }
  840. /**
  841. * Return file real path if file exists
  842. *
  843. * @param string $hash file hash
  844. * @return string
  845. * @author Dmitry (dio) Levashov
  846. **/
  847. public function realpath($hash) {
  848. $path = $this->decode($hash);
  849. return $this->stat($path) ? $path : false;
  850. }
  851. /**
  852. * Return list of moved/overwrited files
  853. *
  854. * @return array
  855. * @author Dmitry (dio) Levashov
  856. **/
  857. public function removed() {
  858. return $this->removed;
  859. }
  860. /**
  861. * Clean removed files list
  862. *
  863. * @return void
  864. * @author Dmitry (dio) Levashov
  865. **/
  866. public function resetRemoved() {
  867. $this->removed = array();
  868. }
  869. /**
  870. * Return file/dir hash or first founded child hash with required attr == $val
  871. *
  872. * @param string $hash file hash
  873. * @param string $attr attribute name
  874. * @param bool $val attribute value
  875. * @return string|false
  876. * @author Dmitry (dio) Levashov
  877. **/
  878. public function closest($hash, $attr, $val) {
  879. return ($path = $this->closestByAttr($this->decode($hash), $attr, $val)) ? $this->encode($path) : false;
  880. }
  881. /**
  882. * Return file info or false on error
  883. *
  884. * @param string $hash file hash
  885. * @param bool $realpath add realpath field to file info
  886. * @return array|false
  887. * @author Dmitry (dio) Levashov
  888. **/
  889. public function file($hash) {
  890. $path = $this->decode($hash);
  891. return ($file = $this->stat($path)) ? $file : $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
  892. if (($file = $this->stat($path)) != false) {
  893. if ($realpath) {
  894. $file['realpath'] = $path;
  895. }
  896. return $file;
  897. }
  898. return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
  899. }
  900. /**
  901. * Return folder info
  902. *
  903. * @param string $hash folder hash
  904. * @param bool $hidden return hidden file info
  905. * @return array|false
  906. * @author Dmitry (dio) Levashov
  907. **/
  908. public function dir($hash, $resolveLink=false) {
  909. if (($dir = $this->file($hash)) == false) {
  910. return $this->setError(elFinder::ERROR_DIR_NOT_FOUND);
  911. }
  912. if ($resolveLink && !empty($dir['thash'])) {
  913. $dir = $this->file($dir['thash']);
  914. }
  915. return $dir && $dir['mime'] == 'directory' && empty($dir['hidden'])
  916. ? $dir
  917. : $this->setError(elFinder::ERROR_NOT_DIR);
  918. }
  919. /**
  920. * Return directory content or false on error
  921. *
  922. * @param string $hash file hash
  923. * @return array|false
  924. * @author Dmitry (dio) Levashov
  925. **/
  926. public function scandir($hash) {
  927. if (($dir = $this->dir($hash)) == false) {
  928. return false;
  929. }
  930. return $dir['read']
  931. ? $this->getScandir($this->decode($hash))
  932. : $this->setError(elFinder::ERROR_PERM_DENIED);
  933. }
  934. /**
  935. * Return dir files names list
  936. *
  937. * @param string $hash file hash
  938. * @return array
  939. * @author Dmitry (dio) Levashov
  940. **/
  941. public function ls($hash) {
  942. if (($dir = $this->dir($hash)) == false || !$dir['read']) {
  943. return false;
  944. }
  945. $list = array();
  946. $path = $this->decode($hash);
  947. foreach ($this->getScandir($path) as $stat) {
  948. if (empty($stat['hidden']) && $this->mimeAccepted($stat['mime'])) {
  949. $list[] = $stat['name'];
  950. }
  951. }
  952. return $list;
  953. }
  954. /**
  955. * Return subfolders for required folder or false on error
  956. *
  957. * @param string $hash folder hash or empty string to get tree from root folder
  958. * @param int $deep subdir deep
  959. * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders
  960. * @return array|false
  961. * @author Dmitry (dio) Levashov
  962. **/
  963. public function tree($hash='', $deep=0, $exclude='') {
  964. $path = $hash ? $this->decode($hash) : $this->root;
  965. if (($dir = $this->stat($path)) == false || $dir['mime'] != 'directory') {
  966. return false;
  967. }
  968. $dirs = $this->gettree($path, $deep > 0 ? $deep -1 : $this->treeDeep-1, $this->decode($exclude));
  969. array_unshift($dirs, $dir);
  970. return $dirs;
  971. }
  972. /**
  973. * Return part of dirs tree from required dir up to root dir
  974. *
  975. * @param string $hash directory hash
  976. * @return array
  977. * @author Dmitry (dio) Levashov
  978. **/
  979. public function parents($hash) {
  980. if (($current = $this->dir($hash)) == false) {
  981. return false;
  982. }
  983. $path = $this->decode($hash);
  984. $tree = array();
  985. while ($path && $path != $this->root) {
  986. $path = $this->_dirname($path);
  987. $stat = $this->stat($path);
  988. if (!empty($stat['hidden']) || !$stat['read']) {
  989. return false;
  990. }
  991. array_unshift($tree, $stat);
  992. if ($path != $this->root) {
  993. foreach ($this->gettree($path, 0) as $dir) {
  994. if (!in_array($dir, $tree)) {
  995. $tree[] = $dir;
  996. }
  997. }
  998. }
  999. }
  1000. return $tree ? $tree : array($current);
  1001. }
  1002. /**
  1003. * Create thumbnail for required file and return its name of false on failed
  1004. *
  1005. * @return string|false
  1006. * @author Dmitry (dio) Levashov
  1007. **/
  1008. public function tmb($hash) {
  1009. $path = $this->decode($hash);
  1010. $stat = $this->stat($path);
  1011. if (isset($stat['tmb'])) {
  1012. return $stat['tmb'] == "1" ? $this->createTmb($path, $stat) : $stat['tmb'];
  1013. }
  1014. return false;
  1015. }
  1016. /**
  1017. * Return file size / total directory size
  1018. *
  1019. * @param string file hash
  1020. * @return int
  1021. * @author Dmitry (dio) Levashov
  1022. **/
  1023. public function size($hash) {
  1024. return $this->countSize($this->decode($hash));
  1025. }
  1026. /**
  1027. * Open file for reading and return file pointer
  1028. *
  1029. * @param string file hash
  1030. * @return Resource
  1031. * @author Dmitry (dio) Levashov
  1032. **/
  1033. public function open($hash) {
  1034. if (($file = $this->file($hash)) == false
  1035. || $file['mime'] == 'directory') {
  1036. return false;
  1037. }
  1038. return $this->_fopen($this->decode($hash), 'rb');
  1039. }
  1040. /**
  1041. * Close file pointer
  1042. *
  1043. * @param Resource $fp file pointer
  1044. * @param string $hash file hash
  1045. * @return void
  1046. * @author Dmitry (dio) Levashov
  1047. **/
  1048. public function close($fp, $hash) {
  1049. $this->_fclose($fp, $this->decode($hash));
  1050. }
  1051. /**
  1052. * Create directory and return dir info
  1053. *
  1054. * @param string $dst destination directory
  1055. * @param string $name directory name
  1056. * @return array|false
  1057. * @author Dmitry (dio) Levashov
  1058. **/
  1059. public function mkdir($dst, $name) {
  1060. if ($this->commandDisabled('mkdir')) {
  1061. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1062. }
  1063. if (!$this->nameAccepted($name)) {
  1064. return $this->setError(elFinder::ERROR_INVALID_NAME);
  1065. }
  1066. if (($dir = $this->dir($dst)) == false) {
  1067. return $this->setError(elFinder::ERROR_TRGDIR_NOT_FOUND, '#'.$dst);
  1068. }
  1069. if (!$dir['write']) {
  1070. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1071. }
  1072. $path = $this->decode($dst);
  1073. $dst = $this->_joinPath($path, $name);
  1074. $stat = $this->stat($dst);
  1075. if (!empty($stat)) {
  1076. return $this->setError(elFinder::ERROR_EXISTS, $name);
  1077. }
  1078. $this->clearcache();
  1079. return ($path = $this->_mkdir($path, $name)) ? $this->stat($path) : false;
  1080. }
  1081. /**
  1082. * Create empty file and return its info
  1083. *
  1084. * @param string $dst destination directory
  1085. * @param string $name file name
  1086. * @return array|false
  1087. * @author Dmitry (dio) Levashov
  1088. **/
  1089. public function mkfile($dst, $name) {
  1090. if ($this->commandDisabled('mkfile')) {
  1091. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1092. }
  1093. if (!$this->nameAccepted($name)) {
  1094. return $this->setError(elFinder::ERROR_INVALID_NAME);
  1095. }
  1096. if (($dir = $this->dir($dst)) == false) {
  1097. return $this->setError(elFinder::ERROR_TRGDIR_NOT_FOUND, '#'.$dst);
  1098. }
  1099. if (!$dir['write']) {
  1100. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1101. }
  1102. $path = $this->decode($dst);
  1103. if ($this->stat($this->_joinPath($path, $name))) {
  1104. return $this->setError(elFinder::ERROR_EXISTS, $name);
  1105. }
  1106. $this->clearcache();
  1107. return ($path = $this->_mkfile($path, $name)) ? $this->stat($path) : false;
  1108. }
  1109. /**
  1110. * Rename file and return file info
  1111. *
  1112. * @param string $hash file hash
  1113. * @param string $name new file name
  1114. * @return array|false
  1115. * @author Dmitry (dio) Levashov
  1116. **/
  1117. public function rename($hash, $name) {
  1118. if ($this->commandDisabled('rename')) {
  1119. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1120. }
  1121. if (!$this->nameAccepted($name)) {
  1122. return $this->setError(elFinder::ERROR_INVALID_NAME, $name);
  1123. }
  1124. if (!($file = $this->file($hash))) {
  1125. return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
  1126. }
  1127. if ($name == $file['name']) {
  1128. return $file;
  1129. }
  1130. if (!empty($file['locked'])) {
  1131. return $this->setError(elFinder::ERROR_LOCKED, $file['name']);
  1132. }
  1133. $path = $this->decode($hash);
  1134. $dir = $this->_dirname($path);
  1135. $stat = $this->stat($this->_joinPath($dir, $name));
  1136. if ($stat) {
  1137. return $this->setError(elFinder::ERROR_EXISTS, $name);
  1138. }
  1139. if (!$this->_move($path, $dir, $name)) {
  1140. return false;
  1141. }
  1142. if (!empty($stat['tmb']) && $stat['tmb'] != "1") {
  1143. $this->rmTmb($stat['tmb']);
  1144. }
  1145. $path = $this->_joinPath($dir, $name);
  1146. $this->clearcache();
  1147. return $this->stat($path);
  1148. }
  1149. /**
  1150. * Create file copy with suffix "copy number" and return its info
  1151. *
  1152. * @param string $hash file hash
  1153. * @param string $suffix suffix to add to file name
  1154. * @return array|false
  1155. * @author Dmitry (dio) Levashov
  1156. **/
  1157. public function duplicate($hash, $suffix='copy') {
  1158. if ($this->commandDisabled('duplicate')) {
  1159. return $this->setError(elFinder::ERROR_COPY, '#'.$hash, elFinder::ERROR_PERM_DENIED);
  1160. }
  1161. if (($file = $this->file($hash)) == false) {
  1162. return $this->setError(elFinder::ERROR_COPY, elFinder::ERROR_FILE_NOT_FOUND);
  1163. }
  1164. $path = $this->decode($hash);
  1165. $dir = $this->_dirname($path);
  1166. return ($path = $this->copy($path, $dir, $this->uniqueName($dir, $this->_basename($path), ' '.$suffix.' '))) == false
  1167. ? false
  1168. : $this->stat($path);
  1169. }
  1170. /**
  1171. * Save uploaded file.
  1172. * On success return array with new file stat and with removed file hash (if existed file was replaced)
  1173. *
  1174. * @param Resource $fp file pointer
  1175. * @param string $dst destination folder hash
  1176. * @param string $src file name
  1177. * @param string $tmpname file tmp name - required to detect mime type
  1178. * @return array|false
  1179. * @author Dmitry (dio) Levashov
  1180. **/
  1181. public function upload($fp, $dst, $name, $tmpname) {
  1182. if ($this->commandDisabled('upload')) {
  1183. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1184. }
  1185. if (($dir = $this->dir($dst)) == false) {
  1186. return $this->setError(elFinder::ERROR_TRGDIR_NOT_FOUND, '#'.$dst);
  1187. }
  1188. if (!$dir['write']) {
  1189. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1190. }
  1191. if (!$this->nameAccepted($name)) {
  1192. return $this->setError(elFinder::ERROR_INVALID_NAME);
  1193. }
  1194. $mime = $this->mimetype($this->mimeDetect == 'internal' ? $name : $tmpname);
  1195. if ($mime == 'unknown' && $this->mimeDetect == 'internal') {
  1196. $mime = elFinderVolumeDriver::mimetypeInternalDetect($name);
  1197. }
  1198. // logic based on http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order
  1199. $allow = $this->mimeAccepted($mime, $this->uploadAllow, null);
  1200. $deny = $this->mimeAccepted($mime, $this->uploadDeny, null);
  1201. $upload = true; // default to allow
  1202. if (strtolower($this->uploadOrder[0]) == 'allow') { // array('allow', 'deny'), default is to 'deny'
  1203. $upload = false; // default is deny
  1204. if (!$deny && ($allow === true)) { // match only allow
  1205. $upload = true;
  1206. }// else (both match | no match | match only deny) { deny }
  1207. } else { // array('deny', 'allow'), default is to 'allow' - this is the default rule
  1208. $upload = true; // default is allow
  1209. if (($deny === true) && !$allow) { // match only deny
  1210. $upload = false;
  1211. } // else (both match | no match | match only allow) { allow }
  1212. }
  1213. if (!$upload) {
  1214. return $this->setError(elFinder::ERROR_UPLOAD_FILE_MIME);
  1215. }
  1216. if ($this->uploadMaxSize > 0 && filesize($tmpname) > $this->uploadMaxSize) {
  1217. return $this->setError(elFinder::ERROR_UPLOAD_FILE_SIZE);
  1218. }
  1219. $dstpath = $this->decode($dst);
  1220. $test = $this->_joinPath($dstpath, $name);
  1221. $file = $this->stat($test);
  1222. $this->clearcache();
  1223. if ($file) { // file exists
  1224. if ($this->options['uploadOverwrite']) {
  1225. if (!$file['write']) {
  1226. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1227. } elseif ($file['mime'] == 'directory') {
  1228. return $this->setError(elFinder::ERROR_NOT_REPLACE, $name);
  1229. }
  1230. $this->remove($file);
  1231. } else {
  1232. $name = $this->uniqueName($dstpath, $name, '-', false);
  1233. }
  1234. }
  1235. $w = $h = 0;
  1236. if (strpos($mime, 'image') === 0 && ($s = getimagesize($tmpname))) {
  1237. $w = $s[0];
  1238. $h = $s[1];
  1239. }
  1240. // $this->clearcache();
  1241. if (($path = $this->_save($fp, $dstpath, $name, $mime, $w, $h)) == false) {
  1242. return false;
  1243. }
  1244. return $this->stat($path);
  1245. }
  1246. /**
  1247. * Paste files
  1248. *
  1249. * @param Object $volume source volume
  1250. * @param string $source file hash
  1251. * @param string $dst destination dir hash
  1252. * @param bool $rmSrc remove source after copy?
  1253. * @return array|false
  1254. * @author Dmitry (dio) Levashov
  1255. **/
  1256. public function paste($volume, $src, $dst, $rmSrc = false) {
  1257. $err = $rmSrc ? elFinder::ERROR_MOVE : elFinder::ERROR_COPY;
  1258. if ($this->commandDisabled('paste')) {
  1259. return $this->setError($err, '#'.$src, elFinder::ERROR_PERM_DENIED);
  1260. }
  1261. if (($file = $volume->file($src, $rmSrc)) == false) {
  1262. return $this->setError($err, '#'.$src, elFinder::ERROR_FILE_NOT_FOUND);
  1263. }
  1264. $name = $file['name'];
  1265. $errpath = $volume->path($src);
  1266. if (($dir = $this->dir($dst)) == false) {
  1267. return $this->setError($err, $errpath, elFinder::ERROR_TRGDIR_NOT_FOUND, '#'.$dst);
  1268. }
  1269. if (!$dir['write'] || !$file['read']) {
  1270. return $this->setError($err, $errpath, elFinder::ERROR_PERM_DENIED);
  1271. }
  1272. $destination = $this->decode($dst);
  1273. if (($test = $volume->closest($src, $rmSrc ? 'locked' : 'read', $rmSrc))) {
  1274. return $rmSrc
  1275. ? $this->setError($err, $errpath, elFinder::ERROR_LOCKED, $volume->path($test))
  1276. : $this->setError($err, $errpath, elFinder::ERROR_PERM_DENIED);
  1277. }
  1278. $test = $this->_joinPath($destination, $name);
  1279. $stat = $this->stat($test);
  1280. $this->clearcache();
  1281. if ($stat) {
  1282. if ($this->options['copyOverwrite']) {
  1283. // do not replace file with dir or dir with file
  1284. if (!$this->isSameType($file['mime'], $stat['mime'])) {
  1285. return $this->setError(elFinder::ERROR_NOT_REPLACE, $this->_path($test));
  1286. }
  1287. // existed file is not writable
  1288. if (!$stat['write']) {
  1289. return $this->setError($err, $errpath, elFinder::ERROR_PERM_DENIED);
  1290. }
  1291. // existed file locked or has locked child
  1292. if (($locked = $this->closestByAttr($test, 'locked', true))) {
  1293. return $this->setError(elFinder::ERROR_LOCKED, $this->_path($locked));
  1294. }
  1295. // remove existed file
  1296. if (!$this->remove($test)) {
  1297. return $this->setError(elFinder::ERROR_REPLACE, $this->_path($test));
  1298. }
  1299. } else {
  1300. $name = $this->uniqueName($destination, $name, ' ', false);
  1301. }
  1302. }
  1303. // copy/move inside current volume
  1304. if ($volume == $this) {
  1305. $source = $this->decode($src);
  1306. // do not copy into itself
  1307. if ($this->_inpath($destination, $source)) {
  1308. return $this->setError(elFinder::ERROR_COPY_INTO_ITSELF, $path);
  1309. }
  1310. $method = $rmSrc ? 'move' : 'copy';
  1311. return ($path = $this->$method($source, $destination, $name)) ? $this->stat($path) : false;
  1312. }
  1313. // copy/move from another volume
  1314. if (!$this->options['copyTo'] || !$volume->copyFromAllowed()) {
  1315. return $this->setError(elFinder::ERROR_COPY, $errpath, elFinder::ERROR_PERM_DENIED);
  1316. }
  1317. if (($path = $this->copyFrom($volume, $src, $destination, $name)) == false) {
  1318. return false;
  1319. }
  1320. if ($rmSrc) {
  1321. if ($volume->rm($src)) {
  1322. $this->removed[] = $file;
  1323. } else {
  1324. return $this->setError(elFinder::ERROR_MOVE, $errpath, elFinder::ERROR_RM_SRC);
  1325. }
  1326. }
  1327. return $this->stat($path);
  1328. }
  1329. /**
  1330. * Return file contents
  1331. *
  1332. * @param string $hash file hash
  1333. * @return string|false
  1334. * @author Dmitry (dio) Levashov
  1335. **/
  1336. public function getContents($hash) {
  1337. $file = $this->file($hash);
  1338. if (!$file) {
  1339. return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
  1340. }
  1341. if ($file['mime'] == 'directory') {
  1342. return $this->setError(elFinder::ERROR_NOT_FILE);
  1343. }
  1344. if (!$file['read']) {
  1345. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1346. }
  1347. return $this->_getContents($this->decode($hash));
  1348. }
  1349. /**
  1350. * Put content in text file and return file info.
  1351. *
  1352. * @param string $hash file hash
  1353. * @param string $content new file content
  1354. * @return array
  1355. * @author Dmitry (dio) Levashov
  1356. **/
  1357. public function putContents($hash, $content) {
  1358. if ($this->commandDisabled('edit')) {
  1359. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1360. }
  1361. $path = $this->decode($hash);
  1362. if (!($file = $this->file($hash))) {
  1363. return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
  1364. }
  1365. if (!$file['write']) {
  1366. return $this->setError(elFinder::ERROR_PERM_DENIED);
  1367. }
  1368. $this->clearcache();
  1369. return $this->_filePutContents($path, $content) ? $this->stat($path) : false;
  1370. }
  1371. /**
  1372. * Extract files from archive
  1373. *
  1374. * @param string $hash archive hash
  1375. * @return array|bool
  1376. * @author Dmitry (dio) Levashov,
  1377. * @author Alexey Sukhotin
  1378. **/
  1379. public function extract($hash) {
  1380. if ($this->commandDisabled('extract')) {
  1381. return $this->setError(elFinder::ERROR_PERM_

Large files files are truncated, but you can click here to view the full file