function file_transfer

Transfers a file to the client using HTTP.

Pipes a file through Drupal to the client.

Parameters

$uri: String specifying the file URI to transfer.

$headers: An array of HTTP headers to send along with file.

Related topics

3 calls to file_transfer()
file_download in drupal/core/includes/file.inc
Page callback: Handles private file transfers.
image_style_deliver in drupal/core/modules/image/image.module
Menu callback; Given a style and image path, generate a derivative.
update_test_mock_page in drupal/core/modules/update/tests/modules/update_test/update_test.module
Page callback: Prints mock XML for the Update Manager module.

File

drupal/core/includes/file.inc, line 1322
API for handling file uploads and server file management.

Code

function file_transfer($uri, $headers) {
  return new StreamedResponse(function () use ($uri) {

    // Transfer file in 1024 byte chunks to save memory usage.
    if (file_exists($uri) && ($fd = fopen($uri, 'rb'))) {
      while (!feof($fd)) {
        print fread($fd, 1024);
      }
      fclose($fd);
    }
  }, 200, $headers);
}