2015-06-22 27 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