2015-11-12 16:32:30 4132次浏览 1条回答 0 悬赏 10 金钱

我想达到的效果是,直接输出图片,但是输出的是乱码,估计是图片的二进制,
因为在1.1中是没问题的,生成图片的代码也可以确定是没问题的。我也考虑过命名空间的问题,但是应该不是问题。
不要说文档里面那种widget的方式,我要的不是那个效果

生成图片的方法部分代码:

header('Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);      
header('Pragma: no-cache');
header("content-type: image/png");

// 输出图像
imagepng(self::$_image); 
imagedestroy(self::$_image);

我直接在浏览器获取Response头,并不是content-type: image/png,而是普通的text/html。
超郁闷。。。。。。。

这是action:

public function actionGetcaptcha() {
//      require_once(Yii::$app->basePath . '/extensions/static/StaticFun.php');
//      include Yii::$app->basePath.'/'.'extensions/yzm2/Captcha.php';
// echo Yii::$app->basePath.'/'.'extensions/yzm2/Captcha.php';

//      use Captcha;
//      $this->setHeader(400);

    $headers = Yii::$app->response->headers;
    $headers->remove('Vary');
    $headers->remove('Content-Encoding');
    
    $headers->set('Vary', '123');
    $headers->set('Content-Encoding', '234');
//      $headers->set('Cache-Control', 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
//      $headers->set('Pragma', 'no-cache');
    $headers->set('Content-Type', 'uuuuuuuuuuuuuu');
    
    var_dump(Yii::$app->response->getHeaders());
    
    
//      var_dump(Yii::$app->response->getHeaders());

    Captcha::$useImgBg = false;             // 是否使用背景图片
    Captcha::$useNoise = false;             // 是否添加杂点
    Captcha::$useCurve = false;             // 是否绘制干扰线
    Captcha::$useZh    = false;             // 是否使用中文验证码
    Captcha::$fontSize = 20;                // 验证码字体大小(像素)
    Captcha::$length   = 4;                 // 验证码字符数
    Captcha::entry();                       // 输出图片

//      header('Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate');
//      header('Cache-Control: post-check=0, pre-check=0', false);
//      header('Pragma: no-cache');
//      header("content-type: image/jpeg");

//      $aa = new CaptchaAction(Yii::$app->controller->action->id, Yii::$app->controller->id);
//      $aa->height = 3;
//      $aa->backColor=0x000000;//背景颜色
//      $aa->maxLength = 6; //最大显示个数
//      $aa->minLength = 5;//最少显示个数
//      $aa->padding = 5;//间距
//      $aa->height=40;//高度
//      $aa->width = 130;  //宽度
//      $aa->foreColor=0xffffff;     //字体颜色
//      $aa->offset=4;        //设置字符偏移量 有效果
//      $aa->run();
//      $aa->runWithParams();
}

求各位神解答啊!救救我

您需要登录后才可以回答。登录 | 立即注册
mymissbook
职场新人

mymissbook

注册时间:2015-11-12
最后登录:2016-01-20
在线时长:2小时23分
  • 粉丝0
  • 金钱35
  • 威望0
  • 积分55

热门问题