function file_transfer in Drupal 6
Same name and namespace in other branches
- 4 includes/file.inc \file_transfer()
- 5 includes/file.inc \file_transfer()
- 7 includes/file.inc \file_transfer()
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
1 call to file_transfer()
- file_download in includes/
file.inc - Call modules that implement hook_file_download() to find out if a file is accessible and what headers it should be transferred with. If a module returns -1 drupal_access_denied() will be returned. If one or more modules returned headers the download…
File
- includes/
file.inc, line 923 - API for handling file uploads and server file management.
Code
function file_transfer($source, $headers) {
if (ob_get_level()) {
ob_end_clean();
}
// IE cannot download private files because it cannot store files downloaded
// over HTTPS in the browser cache. The problem can be solved by sending
// custom headers to IE. See http://support.microsoft.com/kb/323308/en-us
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
drupal_set_header('Cache-Control: private');
drupal_set_header('Pragma: private');
}
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);
}
$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;
}