function ReadableStreamBackupFile::openForRead in Backup and Migrate 8.4
Open a file for reading or writing.
Parameters
bool $binary If true open as a binary file:
Return value
resource
Throws
\Exception
Overrides BackupFileReadableInterface::openForRead
3 calls to ReadableStreamBackupFile::openForRead()
- ReadableStreamBackupFile::readAll in lib/
backup_migrate_core/ src/ File/ ReadableStreamBackupFile.php - Read a line from the file.
- ReadableStreamBackupFile::readBytes in lib/
backup_migrate_core/ src/ File/ ReadableStreamBackupFile.php - Read a line from the file.
- ReadableStreamBackupFile::readLine in lib/
backup_migrate_core/ src/ File/ ReadableStreamBackupFile.php - Read a single line from the file.
File
- lib/
backup_migrate_core/ src/ File/ ReadableStreamBackupFile.php, line 77
Class
- ReadableStreamBackupFile
- Class ReadableStreamBackupFile.
Namespace
BackupMigrate\Core\FileCode
function openForRead($binary = FALSE) {
if (!$this
->isOpen()) {
$path = $this
->realpath();
if (!is_readable($path)) {
// @TODO: Throw better exception
throw new \Exception('Cannot read file.');
}
// Open the file.
$mode = "r" . ($binary ? "b" : "");
$this->handle = fopen($path, $mode);
if (!$this->handle) {
throw new \Exception('Cannot open file.');
}
}
// If the file is already open, rewind it.
$this
->rewind();
return $this->handle;
}