1
0

Files.php 3.9 KB

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