Files.php 3.9 KB

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