files.php 3.8 KB

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