file_transfer

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 – 6 file_transfer($source, $headers)
7 – 8 file_transfer($uri, $headers)

Transfer file using HTTP to client.

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

▾ 2 functions call file_transfer()

file_download in includes/file.inc
Menu handler for private file transfers.
image_style_deliver in modules/image/image.module
Menu callback; Given a style and image path, generate a derivative.

Code

includes/file.inc, line 1915

<?php
function file_transfer($uri, $headers) {
  if (ob_get_level()) {
    ob_end_clean();
  }

  foreach ($headers as $name => $value) {
    drupal_add_http_header($name, $value);
  }
  drupal_send_headers();
  $scheme = file_uri_scheme($uri);
  // Transfer file in 1024 byte chunks to save memory usage.
  if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) {
    while (!feof($fd)) {
      print fread($fd, 1024);
    }
    fclose($fd);
  }
  else {
    drupal_not_found();
  }
  drupal_exit();
}
?>