Skip to content

Commit 383e9ea

Browse files
committedAug 1, 2008
Improved example script and configuration
1 parent 36f1afe commit 383e9ea

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed
 

Diff for: ‎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-
?>

Diff for: ‎nginx.conf

+22-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,34 @@ http {
1414
default_type application/octet-stream;
1515

1616
server {
17-
client_max_body_size 100m;
1817
listen 80;
19-
server_name localhost;
18+
client_max_body_size 100m;
2019

20+
# Upload form should be submitted to this location
2121
location /upload {
22+
# Pass altered request body to this location
2223
upload_pass /test;
23-
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$";
2442
}
2543

44+
# Pass altered request body to a backend
2645
location /test {
2746
proxy_pass http://localhost:8080;
2847
}

0 commit comments

Comments
 (0)