参考:[url]http://bbs.youkuaiyun.com/topics/360220433[/url]
private function outputFile2Brower(){
$filename= WWW_ROOT."../../".$this->request->url;
if (!file_exists($filename)) {
throw RuntimeException("File $filename not found");
}
//TODO:这里应该智能判断type字符串
/*这个做法不对,容易导致一些图片无法显示
header("Content-Type:image/jpg");
header("Content-Length: ".filesize($filename));
readfile($filename);*/
$image = file_get_contents($filename);
//$content=addslashes($image);
header('Content-type: image/jpg');
echo $image;
}
本文介绍了一种使用PHP将图片文件直接输出到浏览器的方法。通过获取文件内容并设置正确的HTTP头来实现。此方法适用于动态地展示服务器上的图片资源。
1505

被折叠的 条评论
为什么被折叠?



