2

cakephp 控制器是否有可能返回一个图像,基本上需要这个来生成验证码图像。我尝试从 /webroot/files/captcha_gen.php 执行它并使用.. $_SESSION [“rand_code”]将代码保存在会话中,但由于某种原因,控制器没有在会话变量列表中显示它..

4

1 回答 1

6

yes it is, of course

you need to set the right headers (using cake2's response class) http://book.cakephp.org/2.0/en/controllers/request-response.html#cakeresponse

then you can just print out the image and it will just be a normal image for the browser:

$this->autoRender = false;
$this->response->type('jpg');
$this->response->body($imageContent);
于 2012-06-15T08:05:57.617 回答