I'm creating a Captcha session by createCaptcha function that i wrote. and in the webservice I call this function to create a Captcha session and image then I want to send Captcha image Or display created Captcha image by webservice that user can send it's value through webservice but I'm facing error. actually instead of a link to that image I get a encoded result when I'm testing it by firefox add-ons soap_client.
any idea where I'm wrong ?
captcha function code :
<?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 "";
}
}
You need to give your
imagepng()
function another parameter to save the picture then withGet_file_content()
function get the content of your image file then encode it to base64 to send viawebservice
inxml
format.