function advagg_missing_file_transfer in Advanced CSS/JS Aggregation 6
Same name and namespace in other branches
- 7 includes/missing.inc \advagg_missing_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.:
1 call to advagg_missing_file_transfer()
- advagg_missing_send_file in ./
advagg.missing.inc - Send the file or send a 307 redirect.
File
- ./
advagg.missing.inc, line 285 - Advanced aggregation module; 404 handler.
Code
function advagg_missing_file_transfer($source, $headers) {
$source = advagg_missing_file_create_path($source);
$fd = fopen($source, 'rb');
// Return if we can't open the file. Will try a 307 in browser to send file.
if (!$fd) {
return;
}
// Clear the buffer.
if (ob_get_level()) {
ob_end_clean();
}
// Add in headers.
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);
}
// Transfer file in 8096 byte chunks.
while (!feof($fd)) {
print fread($fd, 8096);
}
fclose($fd);
exit;
}