You are here

function backup_file::open in Backup and Migrate 6.3

Same name and namespace in other branches
  1. 8.2 includes/files.inc \backup_file::open()
  2. 8.3 includes/files.inc \backup_file::open()
  3. 6.2 includes/files.inc \backup_file::open()
  4. 7.3 includes/files.inc \backup_file::open()
  5. 7.2 includes/files.inc \backup_file::open()

Open a file for reading or writing.

3 calls to backup_file::open()
backup_file::read in includes/files.inc
Read a line from the file.
backup_file::transfer in includes/files.inc
Transfer file using http to client. Similar to the built in file_transfer, but it calls module_invoke_all('exit') so that temp files can be deleted.
backup_file::write in includes/files.inc
Write a line to the file.

File

includes/files.inc, line 351
General file handling code for Backup and Migrate.

Class

backup_file
A backup file which allows for saving to and reading from the server.

Code

function open($write = FALSE, $binary = FALSE) {
  if (!$this->handle) {
    $path = $this
      ->filepath();

    // Check if the file can be read/written.
    if ($write && (file_exists($path) && !is_writable($path) || !is_writable(dirname($path)))) {
      _backup_migrate_message('The file %path cannot be written to.', array(
        '%path' => $path,
      ), 'error');
      return FALSE;
    }
    if (!$write && !is_readable($path)) {
      _backup_migrate_message('The file %path cannot be read.', array(
        '%path' => $path,
      ), 'error');
      return FALSE;
    }

    // Open the file.
    $mode = ($write ? "w" : "r") . ($binary ? "b" : "");
    $this->handle = fopen($path, $mode);
    return $this->handle;
  }
  return NULL;
}