【问题标题】:zend file upload problems. File not receiving when we upload a filezend 文件上传问题。上传文件时未收到文件
【发布时间】:2014-02-16 22:56:46
【问题描述】:

我正在尝试使用 zend 表单上传文件。我已经尝试了很多方法,但是我得到了带有文件名的表单发布数据,但文件没有收到。这是我的代码

 **My Form code**


public function testUploadForm(){

    $imageviewScript = new Zend_Form_Decorator_ViewScript();
    $imageviewScript->setViewScript('image_element.phtml');

    $image_name = new Zend_Form_Element_File('image_name');
    $image_name->setAttrib('enctype', 'multipart/form-data');
     $image_name->addValidator('Extension',false,'jpg,png,gif');
        $image_name->addValidator('Count', false, 1)
        //$image_name->setRequired(true)
                            ->addDecorator($imageviewScript)
                           ->setDecorators($this->setFieldElementDecorators());

     $submit = new Zend_Form_Element_Submit('submit');
    $submit->setLabel('Submit')
    ->setAttrib('class', 'addbutton_6')
    ->removeDecorator('label')
    ->setDecorators($this->getRightSubmitDecorators());

    $this->addElements(array($image_name,$submit));



}

在我用来接收数据的控制器中

public function testuploadAction(){

    $params= array();
    $this->_form->testUploadForm();

    if($this->getRequest()->isPost()){

        $params= $this->getRequest()->getParams();

        $upload= new Zend_File_Transfer_Adapter_Http();
        $upload->setDestination(APPLICATION_PATH.'/../images/uploads/');
        if($uploads->receive()) {
            //Code to process the file goes here
 $filesize = $upload->getFileSize('image_name');

print_r($file_size);退出;

        } else {
            $errors = $upload->getErrors();
        }
        //$formData = $_POST->getValues(); //be sure to call this after receive()
        print_r($formData);exit;
        //$file = $upload->getFileInfo();
        //  $filename = $upload->getFileName('image_name');          //optional info about uploaded file


    }

    $this->_form->populate($params);
    $this->view->form= $this->_form;


}

当我尝试打印数据时,它显示如下警告。

Notice: Undefined index: validators in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 493

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 493

Notice: Undefined index: tmp_name in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 589

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\XXXX\library\Zend\Validate\File\Count.php on line 228

No 没有语法错误。表单已正确提交,但此处未收到文件。 我已将文件元素更改为 Zend 文件元素,提交表单后出现致命错误。

致命错误:在 C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php:1254 中未捕获异常 'Zend_File_Transfer_Exception' 和消息 '"image_name" not found by file transfer adapter'跟踪:#0 C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php(572): Zend_File_Transfer_Adapter_Abstract->_getFiles('image_name') #1 C:\xampp\htdocs\XXXX\ library\Zend\Form\Element\File.php(435): Zend_File_Transfer_Adapter_Abstract->isValid('image_name') #2 C:\xampp\htdocs\XXXX\library\Zend\Form.php(1987): Zend_Form_Element_File->isValid ('shreyansh-ipad ...', Array) #3 C:\xampp\htdocs\XXXX\application\controllers\CustomerController.php(41): Zend_Form->isValid(Array) #4 C:\xampp\htdocs\ XXXX\library\Zend\Controller\Action.php(503): CustomerController->registerAction() #5 C:\xampp\htdocs\XXXX\library\Zend\Controller\Dispatcher\Standard.php(285): Zend_Controller_Action-> dispatch('registerAction') #6 C:\xampp\htdocs\XXXXX\library\Zend\Controller\Front.php(934): Zend_C o 在 C:\xampp\htdocs\XXXXX\library\Zend\File\Transfer\Adapter\Abstract.php 第 1254 行

有人可以建议为什么文件没有为我上传。谢谢。

【问题讨论】:

  • 您是否尝试过对 $_FILES 进行 var 转储?

标签: php zend-framework


【解决方案1】:

我终于找到了解决方案。仅由于表单加密而发生这种情况。为了实现某种网站设计,我在视图文件(即 .phtml 文件)中回显每个字段。所以我使用的是正常形式。即使我将加密类型分配给 zend 表单,它也没有出现在 phtml 表单中,所以现在我设置的文件没有上传

<form enctype="multipart/form-data" method="post" action="" >

现在它工作正常。谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    相关资源
    最近更新 更多