Old Bird talk about PHP Upload file discuz implementation _ PHP Tutorial

Source: Internet
Author: User
Tags form post php file upload upload php
Let's talk about the implementation of discuz in PHP. PHP is still quite common, so I studied PHP to upload files and share it with you here. I hope it will be useful to you. By default, PHP has a maximum upload capacity of 2 MB. it is quite common to upload PHP files. so I have studied how to upload PHP files and share them with you here. I hope it will be useful to you. PHP's default upload limit is 2 MB. to upload files that exceed this setting, you need to adjust some parameters such as PHP and apache.

Next, we will briefly introduce some parameters involved in php file upload: file_uploads allows you to upload files over HTTP. the default value is ON, which means upload_tmp_dir, upload_tmp_dir indicates the temporary directory where files uploaded by PHP are stored. to upload files, ensure that the server does not have the permission to close the temporary files and write the files to the folder, if this parameter is not specified, PHP uses the default value upload_max_filesize to allow the maximum file size to be uploaded. the default value is 2Mpost_max_size.

Controls the maximum data size that PHP can receive in a form submission using the POST method. If you want to use the PHP file upload function, you need to change this value to a value greater than upload_max_filesize. max_input_time limits the time for receiving data through POST, GET, and PUT in seconds. If the running environment of the application is on the low-speed link, you need to add this value to adapt to the more time required to receive data. memory_limit to avoid the large amount of memory available for running scripts, PHP allows you to define the memory usage limit.

Use the memory_limit variable to specify the maximum memory capacity variable memory_limit that a single script program can use. The value of memory_limit should be greater than the value of post_max_size max_execution_time, max_execution_time sets the time for PHP to wait for the script to be executed before the script is forcibly terminated. The time is calculated in seconds. This variable is useful when the script enters an infinite loop state. However, when there is a legal activity that takes a long time to complete (such as uploading large files), this function will also cause operation failure. In this case, you must consider increasing the value of this variable to prevent PHP from shutting down the script for a linux host when the script is executing an important process, it may be in/etc/httpd/conf. d/access. conf/below is php. conf file, which may solve some system file size restrictions.

Use discuz to implement PHP file upload application example

The attachment function of the forum was originally designed not for file management. due to server configuration, php, network, and other factors, uploading files through the forum is not a good solution. If you really need to improve the uploading conditions of Forum attachments, you can try to set the parameters mentioned above in php. ini to meet the needs of uploading large files. At the same time, do not forget to set attachments in the background of the Forum.

At the same time, the following provides configuration guidance from friends who have successfully uploaded large attachments via http. of course, due to the different server configurations and network conditions, this does not necessarily apply to your situation. you may need to modify it in many places: open php. ini,

 
 
  1. Whether file_uploads on allows file upload over HTTP. ON is enabled by default.
  2. Upload_tmp_dir -- upload the file to the place where the temporary file is stored on the server. if it is not specified, the default temporary folder will be used.
  3. Upload_max_filesize 8 m Wangwen business, that is, the maximum file size allowed to be uploaded. The default value is 2 MB.
  4. Post_max_size 8 m refers to the maximum value that can be received by the form POST to PHP, including all values in the form. The default value is 8 MB.

Generally, after the preceding four parameters are set, uploading a file <= 8 m is not a problem under normal network conditions. However, if you want to upload a file larger than 8 m, only the above four items can be set. Unless your network has a high upload speed of 100 MB/s, you must set the following parameters.

 
 
  1. Max_execution_time 600 maximum time (in seconds) for running each PHP page. the default value is 30 seconds.
  2. Max_input_time 600 maximum time required for receiving data on each PHP page. the default value is 60 seconds.
  3. Memory_limit 8 m maximum memory consumed by each PHP page. the default value is 8 M.

After modifying the preceding parameters, you can upload a large volume of files as permitted by the network.


Bytes. The default PHP Upload limit is 2 MB...

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.