function backup_file::transfer in Backup and Migrate 6.3
Same name and namespace in other branches
- 8.2 includes/files.inc \backup_file::transfer()
- 8.3 includes/files.inc \backup_file::transfer()
- 6.2 includes/files.inc \backup_file::transfer()
- 7.3 includes/files.inc \backup_file::transfer()
- 7.2 includes/files.inc \backup_file::transfer()
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.
File
- includes/
files.inc, line 424 - 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 transfer() {
$headers = array(
'Content-Type: ' . $this
->mimetype(),
'Content-Disposition: attachment; filename="' . $this
->filename() . '"',
);
if ($size = $this
->info('filesize')) {
$headers[] = 'Content-Length: ' . $size;
}
// Suppress the warning you get when the buffer is empty.
@ob_end_clean();
if ($this
->open(FALSE, TRUE)) {
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.
while ($data = $this
->read(1024)) {
print $data;
}
$this
->close();
// Ask devel.module not to print it's footer.
$GLOBALS['devel_shutdown'] = FALSE;
}
else {
drupal_not_found();
}
// Start buffering and throw away the results so that errors don't get appended to the file.
ob_start('_backup_migrate_file_dispose_buffer');
backup_migrate_cleanup();
module_invoke_all('exit');
exit;
}