hedera-web/vn/web/util.php

43 lines
876 B
PHP
Raw Normal View History

2016-07-22 20:00:27 +00:00
<?php
namespace Vn\Web;
/**
* Reads a file and writes it to the output buffer.
*
* @param string file The file path
* @param boolean useXsendfile Wether to use the apache module Xsendfile
**/
function printFile ($file, $useXsendfile = FALSE)
{
if (!file_exists ($file))
{
http_response_code (404);
return;
}
$finfo = new \finfo (FILEINFO_MIME_TYPE);
$mimeType = $finfo->file ($file);
if ($useXsendfile)
{
header ("X-Sendfile: $file");
header ("Content-Type: $mimeType");
}
else
{
header ('Content-Description: File Transfer');
header ("Content-Type: $mimeType");
header ('Content-Disposition: attachment; filename="'. basename ($file) .'"');
header ('Expires: 0');
header ('Cache-Control: must-revalidate');
header ('Pragma: public');
header ('Content-Length: '. filesize ($file));
set_time_limit (0);
readfile ($file);
}
}
?>