php&cakephp显示图片的问题参考:
http://bbs.csdn.net/topics/360220433
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Php代码 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; } |