From c50ef570f0428a5f22641bd1cf665a5383c62ecb Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 25 Jun 2008 15:09:28 +0000 Subject: Added grabFile() to the filestore, for much more efficient file reading. git-svn-id: https://code.elgg.org/elgg/trunk@1127 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/filestore.php | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'engine') diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index 1fd292b83..293122586 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -72,6 +72,14 @@ * @return int */ abstract public function tell($f); + + /** + * Get the contents of the whole file. + * + * @param mixed $f The file handle. + * @return mixed The file contents. + */ + abstract public function grabFile($f); /** * Close a given file handle. @@ -191,8 +199,13 @@ } public function delete(ElggFile $file) - { - return unlink($this->getFilenameOnFilestore($file)); + { + $filename = $this->getFilenameOnFilestore($file); + if (file_exists($filename)) { + return unlink($filename); + } else { + return true; + } } public function seek($f, $position) @@ -225,6 +238,12 @@ return $this->dir_root . $this->make_file_matrix($owner->username) . $file->getFilename(); } + + public function grabFile(ElggFile $file) { + + return file_get_contents($file->getFilenameOnFilestore()); + + } /** * Make the directory root. @@ -418,6 +437,18 @@ return $fs->read($this->handle, $length, $offset); } + + /** + * Gets the full contents of this file. + * + * @return mixed The file contents. + */ + public function grabFile() { + + $fs = $this->getFilestore(); + return $fs->grabFile($this); + + } /** * Close the file and commit changes -- cgit v1.2.3