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.

files.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Björn Schießle <schiessle@owncloud.com>
  5. * @author Frank Karlitschek <frank@owncloud.org>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Joas Schilling <nickvergessen@owncloud.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <icewind@owncloud.com>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. *
  13. * @copyright Copyright (c) 2016, ownCloud, Inc.
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. /**
  30. * Public interface of ownCloud for apps to use.
  31. * Files Class
  32. *
  33. */
  34. // use OCP namespace for all classes that are considered public.
  35. // This means that they should be used by apps instead of the internal ownCloud classes
  36. namespace OCP;
  37. /**
  38. * This class provides access to the internal filesystem abstraction layer. Use
  39. * this class exlusively if you want to access files
  40. * @since 5.0.0
  41. */
  42. class Files {
  43. /**
  44. * Recusive deletion of folders
  45. * @return bool
  46. * @since 5.0.0
  47. */
  48. static function rmdirr( $dir ) {
  49. return \OC_Helper::rmdirr( $dir );
  50. }
  51. /**
  52. * Get the mimetype form a local file
  53. * @param string $path
  54. * @return string
  55. * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
  56. * @since 5.0.0
  57. */
  58. static function getMimeType( $path ) {
  59. return \OC::$server->getMimeTypeDetector()->detect($path);
  60. }
  61. /**
  62. * Search for files by mimetype
  63. * @param string $mimetype
  64. * @return array
  65. * @since 6.0.0
  66. */
  67. static public function searchByMime( $mimetype ) {
  68. return(\OC\Files\Filesystem::searchByMime( $mimetype ));
  69. }
  70. /**
  71. * Copy the contents of one stream to another
  72. * @param resource $source
  73. * @param resource $target
  74. * @return int the number of bytes copied
  75. * @since 5.0.0
  76. */
  77. public static function streamCopy( $source, $target ) {
  78. list($count, ) = \OC_Helper::streamCopy( $source, $target );
  79. return $count;
  80. }
  81. /**
  82. * Create a temporary file with an unique filename
  83. * @param string $postfix
  84. * @return string
  85. *
  86. * temporary files are automatically cleaned up after the script is finished
  87. * @deprecated 8.1.0 use getTemporaryFile() of \OCP\ITempManager - \OC::$server->getTempManager()
  88. * @since 5.0.0
  89. */
  90. public static function tmpFile( $postfix='' ) {
  91. return \OC::$server->getTempManager()->getTemporaryFile($postfix);
  92. }
  93. /**
  94. * Create a temporary folder with an unique filename
  95. * @return string
  96. *
  97. * temporary files are automatically cleaned up after the script is finished
  98. * @deprecated 8.1.0 use getTemporaryFolder() of \OCP\ITempManager - \OC::$server->getTempManager()
  99. * @since 5.0.0
  100. */
  101. public static function tmpFolder() {
  102. return \OC::$server->getTempManager()->getTemporaryFolder();
  103. }
  104. /**
  105. * Adds a suffix to the name in case the file exists
  106. * @param string $path
  107. * @param string $filename
  108. * @return string
  109. * @since 5.0.0
  110. */
  111. public static function buildNotExistingFileName( $path, $filename ) {
  112. return(\OC_Helper::buildNotExistingFileName( $path, $filename ));
  113. }
  114. /**
  115. * Gets the Storage for an app - creates the needed folder if they are not
  116. * existant
  117. * @param string $app
  118. * @return \OC\Files\View
  119. * @since 5.0.0
  120. */
  121. public static function getStorage( $app ) {
  122. return \OC_App::getStorage( $app );
  123. }
  124. }