{
protected function xSendFile($path)
{
- if (file_exists($path)) {
- return response(null)->header('Content-Type', Files::_getMimeType($path))->header('X-Sendfile', $path);
+ return self::sendfile($path);
+ }
+
+ public static function sendfile($path, $maxage = 86400)
+ {
+ $response = response(null);
+ $request = request();
+ if (!file_exists($path)) {
+ return $response->setStatusCode(404);
+ }
+ $mtime = filemtime($path);
+ $fsize = filesize($path);
+ $response->header('Content-Type', Files::_getMimeType($path))->header('Content-Length', $fsize)->header('Last-Modified', gmdate('D, d M Y H:i:s T', $mtime));
+ if ($maxage > 0) {
+ $etag = $mtime . '.' . $fsize;
+ $response->header('ETag', '"' . $etag . '"')->header('Cache-Control', 'max-age=' . $maxage);
+ $httpisnotmatch = $request->server('HTTP_IF_NONE_MATCH');
+ if (null !== $httpisnotmatch && $etag === $httpisnotmatch) {
+ return $response->setStatusCode(304);
+ }
} else {
- return response(null)->setStatusCode(404);
+ $response->header('Cache-Control', 'no-store');
}
+ return $response->header('X-Sendfile', $path);
+ }
+
+ public static function sendfileNoCache($path){
+ return self::sendfile($path,0);
}
}