PHP-Zend_Form_Element_Captcha的异常问题?

在我的Zend应用程序中,我遇到了Captcha元素的异常问题.当我尝试查看在本地计算机上使用此Captcha元素的表单时,它工作正常,但是当我将其上载到Debian Server时,它工作不正常… !!!

区别如下:
 

正如您在localhost上看到的那样,验证码中的文本将显示给用户,而在Server [Debian]上,该文本丢失了!

我曾使用followig代码在Zend表单上创建Captcha元素:

    $elements = array();
    $captchaElement = new Zend_Form_Element_Captcha('captcha',
                                                array('label'   => "Ihr generierter Textcode:",
                                                      'captcha' => array('captcha' => 'Image',
                                                      'name'    => 'myCaptcha',
                                                      'wordLen' => 5,
                                                      'timeout' => 300,
                                                      'font'    => 'verdana.ttf',
                                                      'imgDir'  => 'captcha/',
                                                      'imgUrl'  => '/captcha/')
                                                     )
                                                 );
    $elements[] = $captchaElement;
    foreach ($elements as $index => $element)
    {
        $element->setAttrib('tabindex', ($index + 1));
    }

谁能告诉我我在做什么错…?

提前致谢…..

解决方法:

>将此字体更改为其他字体,以检查Debian是否支持它
>设置字体和图像的绝对路径:

$captchaOptions = array(
    'label' => "Enter key",
    'captcha' => array(
        'captcha'   => 'Image',
        'wordLen'   => 4,
        'width'     => 197,
        'timeout'   => 120,
        'expiration'=> 300,
        'font'      => APPLICATION_PATH . '/../public/ttf/arial.ttf',
        'imgDir'    => APPLICATION_PATH . '/../public/images/captcha',
        'imgUrl'    => '/images/captcha/',
        'gcFreq'    => 5
    ),
);

>您使用什么ZF版本?在1.7之后,由于装饰器中存在一个错误,您必须设置自己的装饰器,否则Zend_Captcha无法正常工作:

$captcha = new Zend_Form_Element_Captcha('Captcha', $captchaOptions);
$captchaDecor = array_merge(array(new Decorator_Captcha()), $captcha->getDecorators());
$captcha->setDecorators($captchaDecor);

下面的Decorator_Captcha文件

class Decorator_Captcha extends Zend_Form_Decorator_Abstract
{
    /**
     * Render captcha
     *
     * @param  string $content
     * @return string
     */
    public function render($content)
    {
        $element = $this->getElement();
        if (!method_exists($element, 'getCaptcha')) {
            return $content;
        }

        $view    = $element->getView();
        if (null === $view) {
            return $content;
        }

        $placement = $this->getPlacement();
        $separator = $this->getSeparator();

        $captcha = $element->getCaptcha();
        $markup  = $captcha->render($view, $element);
        switch ($placement) {
            case 'PREPEND':
                $content = $content . $separator . $markup;
                break;
            case 'APPEND':
            default:
                $content = $markup . $separator .  $content;
        }

        return $content;
    }
}
上一篇:【移动开发】Android中Fragment+ViewPager的配合使用


下一篇:除法(Division ,UVA 725)-ACM集训