php&cakephp显示图片的有关问题

原创
2016-06-13 12:32:48 724浏览

php&cakephp显示图片的问题
参考:http://bbs.csdn.net/topics/360220433

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;
    }

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。