免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

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

我有一個簡單的表單,其中包含要上傳的電子郵件和文件,它顯示正確,提交后,它正確地轉(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.icode9.com/content-1-534501.html
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Spring Integration
jQuery-File-Upload 插件使用
Java操作XML文件 dom4j 篇
java web 文件上傳與下載
選擇性復(fù)制select_cpoy.m
Zend Guard Run
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服