Skip to content

Commit 62001a1

Browse files
committed
Version 2.0.4
1 parent fa091be commit 62001a1

File tree

7 files changed

+708
-194
lines changed

7 files changed

+708
-194
lines changed

Changelog

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11

2+
Version 2.0.4
3+
* Fixed bug: location configuration of upload_set_form_field and upload_pass_form_field
4+
was not inheritable from server configuration.
5+
* Added feature: directive upload_aggregate_form_field to pass aggragate properties
6+
of a file like file size, MD5 and SHA1 sums to backend.
7+
* Fixed bug: missing CRLF at the end of resulting body.
8+
* Change: optimized out some unnecessary memory allocations and zeroing.
9+
10+
Version 2.0.3
11+
* upload_store directive was not able to receive more than one argument.
12+
As a result no hashed dirs for file uploads were possible.
13+
* upload_store_access directive did not work at all. Permissions were
14+
defaulted to user:rw. Thanks to Brian Moran.
15+
* In case of any errors at the last chunk of request body only 500 Internal Server Error
16+
was generated intead of 400 Bad Request and 503 Service Unavailable.
17+
* Fixed copyrights for temporary file name generation code
18+
* Fixed compilation issue on 0.6.32. Thanks to Tomas Pollak.
19+
* Added directive upload_pass_form_field to specify fields
20+
to pass to backend. Fixes security hole found by Brian Moran.
21+
222
Version 2.0.2
323
* Fixed crash in logging filename while aborting upload
424
* Added feasible debug logging

LICENCE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* Copyright (c) 2008, Valery Kholodkov
1+
* Copyright (c) 2006, 2008, Valery Kholodkov
22
* All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without

config

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
USE_MD5=YES
2+
USE_SHA1=YES
13
ngx_addon_name=ngx_http_upload_module
24
HTTP_MODULES="$HTTP_MODULES ngx_http_upload_module"
35
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_upload_module.c"

index.php renamed to example.php

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
<?php
22
$header_prefix = 'file';
3-
$upload_dir = 'upload';
43
$slots = 6;
5-
4+
?>
5+
<html>
6+
<head>
7+
<title>Test upload</title>
8+
</head>
9+
<body>
10+
<?
611
if ($_POST){
7-
for ($i=0;$i<=$slots;$i++){
12+
echo "<h2>Uploaded files:</h2>";
13+
echo "<table border=\"2\" cellpadding=\"2\">";
14+
15+
echo "<tr><td>Name</td><td>Location</td><td>Content type</td><td>MD5</td><td>Size</tr>";
16+
17+
for ($i=1;$i<=$slots;$i++){
818
$key = $header_prefix.$i;
919
if (array_key_exists($key."_name", $_POST) && array_key_exists($key."_path",$_POST)) {
1020
$tmp_name = $_POST[$key."_path"];
1121
$name = $_POST[$key."_name"];
12-
$newname = $upload_dir."/".$name;
13-
if (rename($tmp_name, $newname)) {
14-
echo "Moved to $upload_dir successfull<br/>\n";
15-
} else {
16-
echo "Failed to move file<br/>\n";
17-
}
18-
}else{
19-
continue;
22+
$content_type = $_POST[$key."_content_type"];
23+
$md5 = $_POST[$key."_md5"];
24+
$size = $_POST[$key."_size"];
25+
26+
echo "<tr><td>$name</td><td>$tmp_name</td><td>$content_type</td><td>$md5</td><td>$size</td>";
2027
}
2128
}
22-
}else{?>
2329

24-
<html>
25-
<head>
26-
<title>Test upload</title>
27-
</head>
28-
<body>
30+
echo "</table>";
31+
32+
}else{?>
2933
<h2>Select files to upload</h2>
30-
<form name="upload" method="POST" enctype="multipart/form-data" action="/doupload">
34+
<form name="upload" method="POST" enctype="multipart/form-data" action="/upload">
3135
<input type="file" name="file1"><br>
3236
<input type="file" name="file2"><br>
3337
<input type="file" name="file3"><br>
@@ -37,8 +41,7 @@
3741
<input type="submit" name="submit" value="Upload">
3842
<input type="hidden" name="test" value="value">
3943
</form>
44+
<?}
45+
?>
4046
</body>
4147
</html>
42-
43-
<?}
44-
?>

nginx.conf

+22-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ worker_processes 20;
33

44
error_log logs/error.log notice;
55

6-
user root nobody;
76
working_directory /usr/local/nginx;
87

98
events {
@@ -15,15 +14,34 @@ http {
1514
default_type application/octet-stream;
1615

1716
server {
18-
client_max_body_size 100m;
1917
listen 80;
20-
server_name localhost;
18+
client_max_body_size 100m;
2119

20+
# Upload form should be submitted to this location
2221
location /upload {
22+
# Pass altered request body to this location
2323
upload_pass /test;
24-
upload_store /tmp;
24+
25+
# Store files to this directory
26+
# The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
27+
upload_store /tmp 1;
28+
29+
# Allow uploaded files to be read only by user
30+
upload_store_access user:r;
31+
32+
# Set specified fields in request body
33+
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
34+
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
35+
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;
36+
37+
# Inform backend about hash and size of a file
38+
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
39+
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
40+
41+
upload_pass_form_field "^submit$|^description$";
2542
}
2643

44+
# Pass altered request body to a backend
2745
location /test {
2846
proxy_pass http://localhost:8080;
2947
}

0 commit comments

Comments
 (0)