ZendFramework implements multi-file upload.

Source: Internet
Author: User
Tags zend framework
This article mainly introduces how ZendFramework implements the multifile Upload function. a detailed analysis shows the specific steps and related implementation skills of ZendFramework for multifile Upload, for more information about how to use Zend Framework to upload multiple files, see the following example. We will share this with you for your reference. The details are as follows:

Step 1: Find the library folder in our original tutorial .. this is where the Zend class library folder is stored .. add the following folders to the library folder: library/Custom/Controller/Plugin/

Folder is added. at this time, we will find the class file uploaded by our File .. here I name it Upload. php file name .. this file is the class file we will use for file upload. of course, this file is changed to the plug-in form in Zend Framework... upload. some php files are described as follows (I only provide some programs here, that is, simple multifile Upload classes ):

<? Phpclass extends Zend_Controller_Plugin_Abstract {private $ uploaddir; // file Upload path private $ max_files; // The maximum number of private $ max_size files uploaded at a time; // The maximum number of private $ permission files uploaded at a time; // whether the folder can have the permission of private $ files; private $ allowed = array (); // allowed file formats // not allowed file formats private $ notallowed = array ("exe", "mp3"); private $ filesname; // file Form name // the width of the image file. If the width is exceeded, the thumbnail private $ imagewidth is generated. // if the height of the image file is exceeded, the thumbnail priv is generated. Ate $ imageheight; public $ filearray = array (); // return multiple file names public $ lastFileName; // add a public $ Error;?>

Step 2: In the previous course of writing a message book .. find the current controller .. indexController. php, add an Action called upload ). this upload action is used to upload files .. its detailed procedures are as follows:

Public function uploadAction () {echo $ this-> view-> render ('header. phtml '); // display the template header file if (strtolower ($ _ SERVER ['request _ method']) = 'post') {Zend_Loader :: loadClass ('m M _ Controller_Plugin_Upload '); $ uploadfile = new Custom_Controller_Plugin_Upload (ROOT_DIR. '/public/upload/', 'uploadfile', '10', '000000', array ("gif", "png", "jpg", "bmp ", "jpeg"), 600,600); if (''= $ uploadfile-> Error) {echo'

Congratulations! the photo has been uploaded! Please view-> baseUrl. '/index/"> Click here to return

';} Else {echo'

Sorry, the following error occurred when uploading your photo: '. $ uploadfile-> error.' please return and upload again! Please view-> baseUrl. '/index/upload/"> Click here to return

';}} Echo $ this-> view-> render ('message/upload. phtml'); // display the template echo $ this-> view-> render ('footer. phtml'); // display the script file of the template}

Step 3: add the Form function to the View template folder ..: here I added an upload in rijiaddo. phtml template file... in order to let everyone better understand how to upload .. I only write one simple file upload form .. this will not be too difficult to implement... in this View template file .. point the POST action to the upload action to upload the file ..

Last. all you need is to enter your website address .. for example, for my: http: // 127.0.0.1/zendframework/index/upload/, you only select the image file in the upload form .. you can upload the file .. no error. the file you just uploaded will be under the folder zendframework/public/upload/in the website directory .. there is no mistake in testing .. because I only want to upload images .. you can change it to another file you want to upload ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.