我在这里使用MVC模式。
我将index.php
作为基本文件,控制器位于/controllers/
目录中。例如,如果转到/stream/xIEjeEJWqs
,将执行/controllers/streamcontroller.php
。
index.php
像这样启动,它缩小了即将发送到浏览器的输出:
<?php
function replace_tabs_newlines($content)
{
require_once 'includes/min/lib/Minify/HTML.php';
require_once 'includes/min/lib/Minify/CSS_MODIFIED.php';
require_once 'includes/min/lib/JSMin.php';
$content = Minify_HTML::minify($content, array(
'cssMinifier' => array('Minify_CSS', 'minify'),
'jsMinifier' => array('JSMin', 'minify')
));
return $content;
}
ob_start('replace_tabs_newlines');
ob_implicit_flush(0);
...
因此,这段代码最小化了输出的内容,如下所示:
<html>
<head>
<title>
Minifies..
</title>
变成<html><head><title>Minifies..</title>
因此,问题是streamcontroller.php必须输出PNG、MP4和其他内容,当它是readfile()
的内容时,浏览器无法识别一开始被index.php
压缩的内容。
streamcontroller.php摘录:
case "png":
header('Content-type:image/png');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
break;
现在我的问题如下:
从MVC中去掉
streamcontroller.php
,你有什么建议?例如,在index.php
旁边有streamer.php
吗?在
index.php
的replace_tabs_newlines($content)
函数中添加检查函数,以检查浏览器是否指向streamcontroller.php
并且不执行缩小操作?也许有一种方法可以阻止
ob_start()
的回调在即将输出某些内容时被检查?即:streamcontroller.php
中readfile()
之前?我会欣赏在这种情况下被广泛接受的新想法。
在readfile
之前添加一个ob_end_clean
怎么样