]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/FSExt/File.php
privacy_image_cache: checking if the cached file really is an image
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / FSExt / File.php
1 <?php
2
3 /**
4  * File class
5  *
6  * @package Sabre
7  * @subpackage DAV
8  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9  * @author Evert Pot (http://www.rooftopsolutions.nl/)
10  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11  */
12 class Sabre_DAV_FSExt_File extends Sabre_DAV_FSExt_Node implements Sabre_DAV_PartialUpdate_IFile {
13
14     /**
15      * Updates the data
16      *
17      * data is a readable stream resource.
18      *
19      * @param resource|string $data
20      * @return string
21      */
22     public function put($data) {
23
24         file_put_contents($this->path,$data);
25         return '"' . md5_file($this->path) . '"';
26
27     }
28
29     /**
30      * Updates the data at a given offset
31      *
32      * The data argument is a readable stream resource.
33      * The offset argument is a 0-based offset where the data should be
34      * written.
35      *
36      * param resource|string $data
37      * @return void
38      */
39     public function putRange($data, $offset) {
40
41         $f = fopen($this->path, 'c');
42         fseek($f,$offset-1);
43         if (is_string($data)) {
44             fwrite($f, $data);
45         } else {
46             stream_copy_to_stream($data,$f);
47         }
48         fclose($f);
49         return '"' . md5_file($this->path) . '"';
50
51     }
52
53     /**
54      * Returns the data
55      *
56      * @return resource
57      */
58     public function get() {
59
60         return fopen($this->path,'r');
61
62     }
63
64     /**
65      * Delete the current file
66      *
67      * @return bool
68      */
69     public function delete() {
70
71         unlink($this->path);
72         return parent::delete();
73
74     }
75
76     /**
77      * Returns the ETag for a file
78      *
79      * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
80      * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
81      *
82      * Return null if the ETag can not effectively be determined
83      *
84      * @return string|null
85      */
86     public function getETag() {
87
88         return '"' . md5_file($this->path). '"';
89
90     }
91
92     /**
93      * Returns the mime-type for a file
94      *
95      * If null is returned, we'll assume application/octet-stream
96      *
97      * @return string|null
98      */
99     public function getContentType() {
100
101         return null;
102
103     }
104
105     /**
106      * Returns the size of the file, in bytes
107      *
108      * @return int
109      */
110     public function getSize() {
111
112         return filesize($this->path);
113
114     }
115
116 }
117