nginx上傳模塊nginx_upload_module使用


1、安裝模塊

 

1 cd /data/software
3 tar zxvf nginx_upload_module-2.0.12.tar.gz

進入nginx源碼目錄 

1 ./configure --with-http_stub_status_module \ --add-module=/data/software/nginx_upload_module-2.0.12
2 make#新增模塊,不用make install
3 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
4 cp ./objs/nginx /usr/local/nginx/sbin/nginx

 

2、修改配置文件,在server中增加一下內容

 

01 location /upload {
02     upload_pass   /info.php;#上傳完成后端接受處理文件
03     upload_store /data/uptmp;#上傳文件夾
04     upload_limit_rate 1024k;# 限制上傳速度
05     upload_set_form_field "${upload_field_name}_name" $upload_file_name;#文件名稱
06     upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;#文件類型
07     upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;#上傳到的路徑
08     upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;#md5
09     upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;#文件大小
10     upload_pass_form_field "^submit$|^description$";
11     #如果希望把所有的表單字段都傳給后端可以用upload_pass_form_field "^.*$";
12 }

 

 

3、前端代碼

up.html

01 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
02 <html xmlns="http://www.w3.org/1999/xhtml">
03 <head>
04 <title>無標題文檔</title>
05 </head>
06 <body>
07 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
08 <form name="upload" method="POST" enctype="multipart/form-data" action="/upload"><!--提交到上面的/upload-->
09 <input type="file" name="file">
10  
11 <input type="submit" name="submit" value="Upload">
12 </form>
13 </body>
14 </html>

info.php

1 <?php
2     header("Content-Type:text/html; charset=utf-8");
3     print_r($_POST);

上傳會返回如下圖數據

點擊查看原圖

 

from:http://foooy.me/nginx/158.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM