Using the Zend Framework to manage file upload _php tutorials

Source: Internet
Author: User
Tags php file upload upload php zend framework
This article will give the reader a detailed description of how to use the popular Zend Framework to create our own file upload mechanism, which can easily receive, confirm, and process the files to be uploaded.

 First, Introduction

Whether you're managing videos on YouTube, sharing PowerPoint presentations on SlideShare, or using the open source ecommerce platform Magento to update product images in the online store, we have the ability to upload Web-based file uploads. But how does this function work? How is the file transferred from the local machine to the remote server? This article will give the reader a detailed description of how to use the popular Zend Framework to create our own file upload mechanism, which can easily receive, confirm, and process the files to be uploaded.

  Second, the configuration processing file upload PHP

PHP itself can do file uploads via Web forms, but it is necessary to take some time to detect configuration artifacts that directly affect PHP's functionality, whether using standard PHP code or using the Zend Framework to manage file uploads, including:

    • File_uploads: This pseudo-directive enables the PHP file upload feature. By default, this pseudo-directive is enabled.
    • Upload_max_filesize: This pseudo-directive defines the maximum size of the file to be uploaded. By default, this pseudo-directive is set to 2M.
    • Upload_tmp_dir: This pseudo-directive defines the directory where PHP temporarily stores the files to be uploaded, which are temporarily stored in the file before the final destination is passed in, which is specified by the developer. By default, this pseudo-directive does not assign a value, which means that PHP will use the system's default values, for example, many Linux distributions have a temp directory of/tmp.
    • Post_max_size: Sets the maximum size allowed for post data. The default PHP post_max_size is 2M.
    • Max_execution_time: Although the relationship to the file upload is not very close, this pseudo-directive plays an important role in PHP's file upload function because it defines the execution time of the PHP script. For extremely large files, it may take a long time to transfer to the file server, so consider changing the default value of this pseudo-directive to 30 seconds to 60 or even 90 seconds.

  Iii. creating a File Upload form

Below we will create a Web Form sample that can be used to browse the local computer's file system and determine which files to upload. We will do our best to keep the example simple, as shown in appearance 1 of the file upload form that was created.


Figure 11 A simple File Upload form

This form is created in the same way as the other forms we created earlier, but with some slight differences. The HTML code used to create the form is shown in Listing 1. In accordance with the Convention of the Zend Framework, we put this form into a view named Upload.phtml, which is part of the action upload in the controller named Admin.

< form Enctype = " Multipart/form-data " Method = " Post " Action = " /admin/upload " >

< P >
what file would to upload ?< BR />
< input type = " file " name = " Video-upload " size = " + " />
P>

<P>
<input type="Submit"name="Submit" class="Submit"value="Upload Video" />
P>

form>

Listing 1 HTML code for file upload form

In this form, there are two places of code that require extra attention:

  1. Enctype= "Multipart/form-data": this form property should be used when we use Web Forms to send large amounts of binary data. Because files such as spreadsheets and videos contain a large amount of binary data, this property should be included when creating a file upload form.
  2. <input type="file"name="Video-uploadhttp://www.bkjia.com/PHPjc/486448.html www.bkjia.com true http://www.bkjia.com/PHPjc/486448.html techarticle This article will give the reader a detailed description of how to use the popular Zend Framework to create our own file upload mechanism, which can easily receive, confirm, and process the files to be uploaded. ...

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.