linux+nginx+mysql+php system Modify File Upload size limit

Source: Internet
Author: User
Tags php file upload rar zip

PHP File Upload function configuration mainly involves php.ini configuration file Upload_tmp_dir, Upload_max_filesize, post_max_size and other parameters, Nginx is client_max_body_size.
1. Modify PHP configuration file (php.ini)
①file_uploads = On
HTTP file uploads are allowed by default, and this option must be set to ON.
②upload_tmp_dir =
Default is empty
③upload_max_filesize = 2M
Default upload_max_filesize = 2M, that is, the size of the file upload is 2M, if you want to upload more than 8M of files, such as 20M, you must set upload_max_filesize = 20M.
④post_max_size = 8M
Modifies the post_max_size option in the php.ini configuration file, which represents the maximum byte length of data allowed for post, and the default is 8M. If the post data exceeds the limit, then $_post and $_files will be empty. To upload large files, you must set the value of this option is greater than the value of the upload_max_filesize instruction, generally set upload_max_filesize and post_max_size values equal. In addition, if the memory limit is enabled, the value should be less than the value of the Memory_limit option.
⑤max_execution_time
When uploading large files, if the network speed is very slow, when more than a certain time, will report the script execution more than 30 seconds error, because in the php.ini configuration file max_execution_time configuration parameters, which indicates the maximum allowable execution time (seconds), 0 means no limit. You can adjust the Max_execution_time value appropriately, not recommend setting to 0.
2. Reload the PHP configuration file
Lnmp PHP is the fast-cgi mode, is a separate service, so to restart PHP alone.
/USR/LOCAL/PHP/SBIN/PHP-FPM Reload
3. Modify Nginx configuration file (nginx.conf)
Look for client_max_body_size in the nginx.conf file to set the value that you want to set.
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
Location ~. php$ {
Root/home/www/htdocs;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/home/www/htdocs$fastcgi_script_name;
Include Fastcgi_params;

Client_max_body_size 35m; #客户端上传文件大小设为35M
Client_body_temp_path/home/www/nginx_temp; #设置临时目录
}
4. reload Nginx configuration file
/usr/local/nginx/sbin/nginx-s Reload
"Another: (PHP 5.2.12 and above version) upload the maximum number of files at one time." Need to modify the number of max_file_uploads, in addition, PHP seems to be in the version 5.3.21 error, set the Max_file_uploads value does not work. 】
5. Use the Phpinfo () function to see if PHP is in effect and test the upload

===== Upload Test Code = =

The code is as follows Copy Code

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<form action= "" method= "Post" enctype= "Multipart/form-data" Name= "Form1" >
<input type= "File" name= "Up_file"/>
<input type= "text" name= "url" id= "url"/>
<input type= "Submit" name= "Upload" value= "Upload"/>
</form>
<?php
if (!empty ($_files[up_file][name])) {
if (!is_dir ("Upfile")) {
mkdir ("Upfile");
}
$path = "Upfile";
$fileinfo = $_files[up_file];
$type =strstr ($fileinfo [name], ".");
$fileinfo [' name '] = ' upfile/'. Time (). Rand (100,999). $type;
$fileinfo [' tmp_name '] = "upfile";
Exit (Print_r ($fileinfo));
Echo $type;
if ($type!= ". rar" && $type!= ". zip") {
echo "File type Error! Only allow the upload zip or rar format Compression pack! ";

}else{
Move_uploaded_file ($fileinfo [' Tmp_name '], $fileinfo [' name ']);
?>
<script> alert ("12313");d ocument.getelementbyid (' url '). Value = <?php echo $fileinfo [' name '];? ></script>
<?php
echo "Upload success";

}
}
?>

Related Article

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.