You are here

function backup_migrate_file_transfer in Backup and Migrate 5.2

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.

Parameters

$info An info array (as returned by backup_migrate_file_info) for the file.:

2 calls to backup_migrate_file_transfer()
backup_migrate_destination_browser_save in includes/destinations.browser.inc
Browser download destination callback.
backup_migrate_ui_destination_download_file in includes/destinations.inc
Download a file to the browser.

File

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

Code

function backup_migrate_file_transfer($info) {
  $headers = array(
    'Content-Type: ' . ($info['filemime'] ? $info['filemime'] : 'application/octet-stream'),
    'Content-Disposition: attachment; filename="' . $info['filename'] . '"',
  );
  if ($info['filesize']) {
    $headers[] = 'Content-Length: ' . $info['filesize'];
  }
  ob_end_clean();
  foreach ($headers as $header) {

    // To prevent HTTP header injection, we delete new lines that are
    // not followed by a space or a tab.
    // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
    $header = preg_replace('/\\r?\\n(?!\\t| )/', '', $header);
    drupal_set_header($header);
  }

  // Transfer file in 1024 byte chunks to save memory usage.
  if ($fd = fopen($info['filepath'], 'rb')) {
    while (!feof($fd)) {
      print fread($fd, 1024);
    }
    fclose($fd);
  }
  else {
    drupal_not_found();
  }
  module_invoke_all('exit');
  exit;
}