File.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\FS;
  4. use Sabre\DAV;
  5. /**
  6. * File class.
  7. *
  8. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  9. * @author Evert Pot (http://evertpot.com/)
  10. * @license http://sabre.io/license/ Modified BSD License
  11. */
  12. class File extends Node implements DAV\IFile
  13. {
  14. /**
  15. * Updates the data.
  16. *
  17. * @param resource $data
  18. */
  19. public function put($data)
  20. {
  21. file_put_contents($this->path, $data);
  22. clearstatcache(true, $this->path);
  23. }
  24. /**
  25. * Returns the data.
  26. *
  27. * @return resource
  28. */
  29. public function get()
  30. {
  31. return fopen($this->path, 'r');
  32. }
  33. /**
  34. * Delete the current file.
  35. */
  36. public function delete()
  37. {
  38. unlink($this->path);
  39. }
  40. /**
  41. * Returns the size of the node, in bytes.
  42. *
  43. * @return int
  44. */
  45. public function getSize()
  46. {
  47. return filesize($this->path);
  48. }
  49. /**
  50. * Returns the ETag for a file.
  51. *
  52. * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
  53. * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
  54. *
  55. * Return null if the ETag can not effectively be determined
  56. *
  57. * @return mixed
  58. */
  59. public function getETag()
  60. {
  61. return '"'.sha1(
  62. fileinode($this->path).
  63. filesize($this->path).
  64. filemtime($this->path)
  65. ).'"';
  66. }
  67. /**
  68. * Returns the mime-type for a file.
  69. *
  70. * If null is returned, we'll assume application/octet-stream
  71. *
  72. * @return mixed
  73. */
  74. public function getContentType()
  75. {
  76. return null;
  77. }
  78. }