小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

PHP-如何在Zend中實現(xiàn)文件上傳?

 印度阿三17 2019-10-30

我有一個簡單的表單,其中包含要上傳的電子郵件和文件,它顯示正確,提交后,它正確地轉(zhuǎn)到了我設(shè)置的結(jié)果頁面.
但是,我現(xiàn)在找不到服務(wù)器上的文件.

這是我的代碼:

形成:

 public function init()
    {
        /* Form Elements & Other Definitions Here ... */

        $this->setName('form-counting');

        $email = new Zend_Form_Element_Text('email');
        $email -> setLabel('Name:')
                    ->addFilter('StripTags')
                    ->addValidator('NotEmpty', true)
                    ->addValidator('EmailAddress')
                    ->setRequired(true);
        $this->addElement($email);

        $UP_file = new Zend_Form_Element_File('UP_file');
        $UP_file->setLabel('Upload files:')
            ->setRequired(true)
        $this->addElement($UP_file);


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

    }

我究竟做錯了什么?謝謝

解決方法:

在控制器上,您需要一個適配器來接收文件. Zend_File_Transfer_Adapter_Http是一個簡單的解決方案.您應(yīng)該在接收文件的適配器中設(shè)置接收目的地.

控制器:

public function indexAction()
{
    // action body
    $eform = new Application_Form_Eform();
    if ($this->_request->isPost())
    {
        $formData = $this->_request->getPost();
        if ($eform->isValid($formData))
        {
            $nameInput  =   $eform->getValue('email');

            //receiving the file:
            $adapter = new Zend_File_Transfer_Adapter_Http();
            $files = $adapter->getFileInfo();

            // You should know the base path on server where you need to store the file.
            // You can put the server local address in Zend Registry in bootstrap,
            // then have it here like: Zend_Registry::get('configs')->...->basepath or something like that.
            // I just assume you will fix it later:
            $basePath = "/your_local_address/a_folder_for_unsafe_files/";

            foreach ($files as $file => $info) {
                // set the destination on server:
                $adapter->setDestination($basePath, $file);

                // sometimes it would be a good idea to rename the file.
                // I left it for you to do it here:
                $fileName = $info['name'];
                $adapter->addFilter('Rename', array('target' => $fileName), $file);
                $adapter->receive($file);

                // You can make sure of having the file:
                if (file_exists($filePath . $fileName)) {
                    // you can move, copy or change the file before redirecting to the new page.
                    // Or you might need to keep the track of files and email in a database.
                } else {
                    // throw error if you want.
                }
            }
        } 

        // Then redirect:
        $this->_helper->redirector->gotoRouteAndExit (array(
            'controller' => 'index',
            'action'     =>'result', 
            'email'      => $nameInput)); 

    }


    $this->view->form = $eform;
}
來源:https://www./content-1-534501.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多