zend框架上传图片虚假扩展文件上传

时间:2011-03-24 12:25:44

标签: zend-framework file forms upload

这是我的表单代码,我在上传时遇到错误:“文件'swing-layout-1.0.4-src.zip'有一个错误的扩展”

<?php

class Admin_Form_Banner extends ZendX_Form_Designed {

    public function init() {
        $this->setEnctype(self::ENCTYPE_MULTIPART);
        $this->setMethod(self::METHOD_POST);
        $this->setMethod('post');

        // Add an email element
        $this->addElement('text', 'banner_title', array(
            'label' => 'Banner Title',
            'required' => true,
            'filters' => array('StringTrim')
        ));

        $this->addElement('text', 'banner_type', array(
            'label' => 'Banner Type',
            'required' => true,
            'filters' => array('StringTrim')
        ));


        $this->addElement('checkbox', 'is_active', array(
            'label' => 'Is Active',
            'required' => true,
            'filters' => array('StringTrim')
        ));

        $banner_position = new Zend_Form_Element_Select('banner_position');
        $banner_position->setMultiOptions($this->getBannerPositions())->setLabel('Banner Position');

        $this->addElement($banner_position, 'banner_position');



        $file = new Zend_Form_Element_File('file');
        $file->addValidator('Count', FALSE, 1);
        $file->addValidator('Size', FALSE, 67633152);
        $file->addValidator('Extension', false,'.zip,rar');
        $file->setRequired(FALSE);
        $file->setAllowEmpty(false);
        $this->addElement($file, 'file_path', array('label' => 'Attacehd file'));


        $this->addElement('submit', 'submit', array(
            'ignore' => true,
            'label' => ''
        ));
    }

    public function getBannerPositions() {
        $db = Zend_Db_Table::getDefaultAdapter();

        $bannerPosition = $db->fetchPairs($db
                                ->select()
                                ->from('banner_position'), array('id', 'banner_position'));
        return $bannerPosition;
    }

}

1 个答案:

答案 0 :(得分:1)

我认为应该有'zip,rar'而不是'.zip,rar'