无法通过 nusoap webservice 发送验证码图像

Can not send Captcha image through nusoap webservice

我正在通过我编写的 createCaptcha 函数创建验证码会话。 在 web 服务中,我调用此函数来创建验证码会话和图像,然后我想发送验证码图像或显示由 web 服务创建的验证码图像,用户可以通过 web 服务发送它的值,但我遇到了错误。 实际上,当我通过 firefox 附加组件 soap_client 对其进行测试时,我得到的是编码结果,而不是对该图像的 link。

知道我哪里错了吗?

验证码功能代码:

<?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 soap Class :

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


}

您需要为 imagepng() 函数提供另一个参数来保存图片,然后使用 Get_file_content() 函数获取图像文件的内容,然后将其编码为 base64 以通过 webservice 发送采用 xml 格式。

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


}