public function readFile($path, $name)
{
// Create a temporary file and register it for deletion at the
// end of this request.
if (!($localFile = Horde_Util::getTempFile('vfs'))) {
throw new Horde_Vfs_Exception('Unable to create temporary file.');
}
if (is_callable(array($this, 'readStream'))) {
// Use a stream from the VFS if possible, to avoid reading all data
// into memory.
$stream = $this->readStream($path, $name);
if (!($localStream = fopen($localFile, 'w'))) {
throw new Horde_Vfs_Exception('Unable to open temporary file.');
}
stream_copy_to_stream($stream, $localStream);
fclose($localStream);
} else {
// We have to read all of the data in one shot.
$data = $this->read($path, $name);
file_put_contents($localFile, $data);
}
// $localFile now has $path/$name's data in it.
return $localFile;
}