function file_transfer
file_transfer($uri, $headers)
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
File
- includes/file.inc, line 1955
- API for handling file uploads and server file management.
Code
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(); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!file.inc/function/file_transfer/7.x