Zend Framework implements multiple file upload function examples, zendframework_PHP tutorial

WBOY
Release: 2016-07-12 08:56:07
Original
942 people have browsed it

Zend Framework implements the multi-file upload function example, zendframework

This article describes the Zend Framework method of implementing the multi-file upload function. Share it with everyone for your reference, the details are as follows:

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

We have finished adding the folder. Now we have to find the class file for our file upload. Here I named it Upload.php file name. This file is the class file we will use for file upload. Of course, I rewrote this file into a plug-in form in Zend Framework... Part of the file description of Upload.php is as follows (I only give part of the program here, which is a simple multi-file upload class):

<&#63;php
class Custom_Controller_Plugin_Upload extends Zend_Controller_Plugin_Abstract {
private $uploaddir; //文件上传存路径
private $max_files; //一次性最多上传多少文件
private $max_size; //文件最大量
private $permission; //文件夹是否可以有权限
private $files;
private $allowed = array (); //允许上传文件格式
//不允许上传文件格式
private $notallowed = array ("exe", "mp3" );
private $filesname; //文件表单name
//图片文件宽度,超过就生成缩略图
private $imagewidth; //图片文件高度,超过就生成缩略图
private $imageheight;
public $filearray = array ();
//返回多个文件名
public $lastFileName; //返加一个文件名
public $Error;
&#63;>

Copy after login

Step 2: In our previous tutorial on writing a guestbook...find the controller at that time...IndexController.php, and add an action called upload. This upload action is for uploading files. The detailed procedure for using it is as follows:

public function uploadAction() {
echo $this->view->render('header.phtml');//显示模版头文件
if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
Zend_Loader::loadClass('Custom_Controller_Plugin_Upload');
$uploadfile=new Custom_Controller_Plugin_Upload( ROOT_DIR.'/public/upload/','uploadfile','10','2048000', array("gif","png","jpg","bmp","jpeg"),600,600);
if(''==$uploadfile->Error){
echo '<div class="commentInner" style="width:860px;text-align:center;">
恭喜您,照片上传成功!请您<a style="color:red;" href=
"'.$this->view->baseUrl.'/index/index/">点这里返回</a></div>';
}else{
echo '<div class="commentInner" style="width:860px;text-align:center;">
对不起,您照片上传有以下错误:'.$uploadfile->error.'请返回重新上传!请您
<a style="color:red;" href="'.$this->view->baseUrl.'/index/upload/">
点这里返回</a></div>';
}
}
echo $this->view->render('message/upload.phtml');//显示模版
echo $this->view->render('footer.phtml');//显示模版脚文件
}

Copy after login

Step 3: Add the upload function Form form to our View template folder...: Here I have added an upload.phtml template file in Riga... In order to let everyone better see how to implement uploading. .I will only write the simplest file upload form. It will not be too difficult to implement... We only need to point its POST action to our upload action in this View template file to upload files. Got it..

Finally, all you need is to enter your website address. For example, mine: http://127.0.0.1/zendframework/index/upload/ This only requires you to select the image file in the upload form.. and you can upload it. Okay.. If there is nothing wrong, the file you just uploaded will be under the folder zendframework/public/upload/ in the website directory. There will be no mistakes in the test. Because I only control uploading as image files here. You can change it. into other files you want to upload..

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.

Articles you may be interested in:

  • Zend Framework Tutorial - Zend_Db_Table_Rowset Usage Example Analysis
  • Zend Framework Tutorial - Zend_Db_Table_Row Usage Example Analysis
  • Zend Framework Tutorial: Detailed explanation of Zend_Db_Table usage
  • Zend Framework tutorial: Zend_Form component to implement form submission and display error prompts
  • Zend Framework development introduction classic tutorial
  • Zend Framework Smarty extension implementation Method
  • Zend Framework routing mechanism code analysis
  • Zend Framework implements a guestbook with basic functions (with demo source code download)
  • Zend Framework implements session storage in memcache Method
  • Detailed explanation of usage of Zend Framework paging class
  • Environment configuration for getting started with Zend Framework and the first Hello World example (with demo source code download)
  • Link to Zend Framework tutorial Database and method to perform add/delete query (with demo source code download)
  • Detailed explanation of the Zend_Db_Table table association instance in the Zend Framework tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1113737.htmlTechArticleZend Framework implements an example of multi-file upload function, zendframework This example describes how Zend Framework implements multi-file upload function. Share it with everyone for your reference, the details are as follows...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template