file_transfer

Versions
4.6 – 6
file_transfer($source, $headers)
7
file_transfer($uri, $headers)

Transfer file using http to client. Pipes a file through Drupal to the client.

Parameters

$source File 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
Call modules to find out if a file is accessible for a given user.
upload_download in modules/upload.module

Code

includes/file.inc, line 456

<?php
function file_transfer($source, $headers) {
  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);
    header($header);
  }

  $source = file_create_path($source);

  // Transfer file in 1024 byte chunks to save memory usage.
  if ($fd = fopen($source, 'rb')) {
    while (!feof($fd)) {
      print fread($fd, 1024);
    }
    fclose($fd);
  }
  else {
    drupal_not_found();
  }
  exit();
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.