aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-25 15:09:28 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-25 15:09:28 +0000
commitc50ef570f0428a5f22641bd1cf665a5383c62ecb (patch)
tree264e209bfa615716ee3d8e8396c0d442ad69406e
parent7d49e67a72a814f6261712390521531dfd7d0a33 (diff)
downloadelgg-c50ef570f0428a5f22641bd1cf665a5383c62ecb.tar.gz
elgg-c50ef570f0428a5f22641bd1cf665a5383c62ecb.tar.bz2
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
-rw-r--r--engine/lib/filestore.php35
1 files changed, 33 insertions, 2 deletions
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