public function writeFile($fileName, $content = null, $mimeType = null, $headers = null, $forceDownload = true, $clientFileName = null, $fileSize = null)
{
static $defaultMimeTypes = array('css' => 'text/css', 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'htm' => 'text/html', 'html' => 'text/html', 'js' => 'javascript/js', 'pdf' => 'application/pdf', 'xls' => 'application/vnd.ms-excel');
if ($mimeType === null) {
$mimeType = 'text/plain';
if (function_exists('mime_content_type')) {
$mimeType = mime_content_type($fileName);
} else {
if (($ext = strrchr($fileName, '.')) !== false) {
$ext = substr($ext, 1);
if (isset($defaultMimeTypes[$ext])) {
$mimeType = $defaultMimeTypes[$ext];
}
}
}
}
if ($clientFileName === null) {
$clientFileName = basename($fileName);
} else {
$clientFileName = basename($clientFileName);
}
if ($fileSize === null || $fileSize < 0) {
$fileSize = $content === null ? filesize($fileName) : strlen($content);
}
$this->sendHttpHeader();
if (is_array($headers)) {
foreach ($headers as $h) {
header($h);
}
} else {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Type: {$mimeType}");
$this->_contentTypeHeaderSent = true;
}
header('Content-Length: ' . $fileSize);
header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"{$clientFileName}\"");
header('Content-Transfer-Encoding: binary');
if ($content === null) {
readfile($fileName);
} else {
echo $content;
}
}