2015-06-22 59 views
0

我通过createCaptcha函数创建了一个验证码会话,该代码由我编写。 和在web服务我调用这个函数来创建一个验证码会话和图像,然后我想发送验证码图像或显示创建验证码图像的web服务,用户可以通过web服务发送它的价值,但我面临的错误。 实际上,而不是一个链接到该图像我得到一个编码的结果,当我测试它由Firefox加载项soap_client。无法通过nusoap webservice发送验证码图片

任何想法,我错了?

验证码功能代码:

<?php 
session_start(); 

function createcaptcha($imgname) 
{ 
    /* Attempt to open */ 
    $im = @imagecreatefromjpeg($imgname); 

    /* See if it failed */ 
    if(!$im) 
    { 
     /* Create a black image */ 
     $code=rand(1000,9999); 
     $_SESSION["code"]=$code; 
     $im = imagecreatetruecolor(50, 24); 
     $bg = imagecolorallocate($im, 22, 86, 165); 
     $fg = imagecolorallocate($im, 255, 255, 255); 
     imagefill($im, 0, 0, $bg); 
     /* Output an captcha code */ 
     imagestring($im, 5, 5, 5, $code, $fg); 
    } 

    return $im; 
} 

GetCaptcha皂类:

session_start(); 
include_once('captcha.php'); 

class getCaptcha extends DBM 
{ 
    public function getcaptcha() 
    { 
     //creating and generating captcha image and code 
     $img = createcaptcha('captcha.png'); 


     //encoding to base64 
     //$base64 = base64_encode($img); 

     $path = $img; 
     $type = pathinfo($path, PATHINFO_EXTENSION); 
     $data = file_get_contents($path); 
     $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data); 

     $save = "/captchafile/captcha.png"; 
     imagepng($base64, $save); 


     $captcha=$save; 

     $this->strResult = ""; 


      $this->strResult.="<captcha>"; 
      $this->strResult.="<captcha>$captcha</captcha>"; 
      $this->strResult.="</captcha>"; 


    } 


    function __toString() 
    { 
     if($this->strResult!=""){ 
      return $this->strResult; 
     } 
     return ""; 
    } 


} 

回答

0

你需要给你的imagepng()功能的其他参数,然后将图片保存与Get_file_content()功能让您的图像文件的内容然后将其编码为base64,通过webservicexml格式发送。

include_once('captcha.php'); 

class getCaptcha extends DBM 
{ 
    public function getcaptcha($dump) 
    { 
     //creating and generating captcha image and code 
     $img = createcaptcha("Captcha.png"); 

     imagepng($img,"Captcha.png"); 
     imagedestroy($img); 

     $captchafile = file_get_contents('./Captcha.png'); 

     //encoding to base64 
     $base64 = base64_encode($captchafile); 


     $captcha=$base64; 

     $this->strResult = ""; 


      $this->strResult.="<captcha>"; 
      $this->strResult.="<captcha>$captcha</captcha>"; 
      $this->strResult.="</captcha>"; 


    } 


    function __toString() 
    { 
     if($this->strResult!=""){ 
      return $this->strResult; 
     } 
     return ""; 
    } 


} 
+0

非常感谢。解决了我的问题。我没有考虑编码它..! – anonymox