【问题标题】:Pyrocms front end controller - can't output image to the browserPyrocms 前端控制器 - 无法将图像输出到浏览器
【发布时间】:2011-10-09 10:20:41
【问题描述】:

下面是代码

class Home extends Public_Controller
{
    /**
     * Constructor method
     *`enter code here`
     * @author PyroCMS Dev Team
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();  
    }


public function testimg(){
    header("Content-type: image/png");
    $image = imagecreatetruecolor(200, 200);
    imagepng($image);     
}
}

但是当我像(http://localhost/sitename/home/testimg)一样调用这个控制器时。 我收到以下错误

图片“http://localhost/sitename/home/testimg”无法显示,因为它包含错误。

请帮我解决这个问题,我是 pyrocms 的新手。

【问题讨论】:

    标签: codeigniter pyrocms gd2


    【解决方案1】:

    问题已解决:当回显某些内容时,总会有一个额外的空格,我不知道为什么 - ob_clean() 可以完成这项工作.

    public function testimg(){
        ob_clean();
        header("Content-type: image/png");
        $image = imagecreatetruecolor(200, 200);
        imagepng($image);     
    }
    

    【讨论】:

      【解决方案2】:

      这与 PyroCMS 甚至 CodeIgniter 无关,您只是设置了错误的图像。这是一个通用的 PHP 错误。

      【讨论】:

      • 感谢您的建议。但我认为这不是一般的 php 错误,因为当我将此代码放在单独的文件中时,它可以正常工作。例如。 这将输出一个宽度为 200、高度为 200 的黑色图像。但在 pyrocms 控制器中它不起作用。任何快速帮助都会得到帮助。谢谢
      猜你喜欢
      • 2012-08-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多