files.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Public interface of ownCloud for apps to use.
  24. * Files Class
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. /**
  31. * This class provides access to the internal filesystem abstraction layer. Use
  32. * this class exlusively if you want to access files
  33. */
  34. class Files {
  35. /**
  36. * Recusive deletion of folders
  37. * @return bool
  38. */
  39. static function rmdirr( $dir ) {
  40. return \OC_Helper::rmdirr( $dir );
  41. }
  42. /**
  43. * Get the mimetype form a local file
  44. * @param string $path
  45. * @return string
  46. * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
  47. */
  48. static function getMimeType( $path ) {
  49. return(\OC_Helper::getMimeType( $path ));
  50. }
  51. /**
  52. * Search for files by mimetype
  53. * @param string $mimetype
  54. * @return array
  55. */
  56. static public function searchByMime( $mimetype ) {
  57. return(\OC\Files\Filesystem::searchByMime( $mimetype ));
  58. }
  59. /**
  60. * Copy the contents of one stream to another
  61. * @param resource $source
  62. * @param resource $target
  63. * @return int the number of bytes copied
  64. */
  65. public static function streamCopy( $source, $target ) {
  66. list($count, $result) = \OC_Helper::streamCopy( $source, $target );
  67. return $count;
  68. }
  69. /**
  70. * Create a temporary file with an unique filename
  71. * @param string $postfix
  72. * @return string
  73. *
  74. * temporary files are automatically cleaned up after the script is finished
  75. */
  76. public static function tmpFile( $postfix='' ) {
  77. return(\OC_Helper::tmpFile( $postfix ));
  78. }
  79. /**
  80. * Create a temporary folder with an unique filename
  81. * @return string
  82. *
  83. * temporary files are automatically cleaned up after the script is finished
  84. */
  85. public static function tmpFolder() {
  86. return(\OC_Helper::tmpFolder());
  87. }
  88. /**
  89. * Adds a suffix to the name in case the file exists
  90. * @param string $path
  91. * @param string $filename
  92. * @return string
  93. */
  94. public static function buildNotExistingFileName( $path, $filename ) {
  95. return(\OC_Helper::buildNotExistingFileName( $path, $filename ));
  96. }
  97. /**
  98. * Gets the Storage for an app - creates the needed folder if they are not
  99. * existant
  100. * @param string $app
  101. * @return \OC\Files\View
  102. */
  103. public static function getStorage( $app ) {
  104. return \OC_App::getStorage( $app );
  105. }
  106. }