Skip to content

Commit 8343450

Browse files
committed
Added sample script and sample configuration for unzip filter
1 parent d1ff206 commit 8343450

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

example-unzip.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
$header_prefix = 'file';
3+
?>
4+
<html>
5+
<head>
6+
<title>Test upload</title>
7+
</head>
8+
<body>
9+
<?
10+
if ($_POST){
11+
echo "<h2>Uploaded files:</h2>";
12+
13+
echo "<table border=\"2\" cellpadding=\"2\">";
14+
15+
echo "<tr><td>Archive path</td><td>File name</td><td>Location</td><td>Content type</td><td>MD5</td><td>Size</tr>";
16+
17+
$fdesc_keys = array_keys($_POST);
18+
19+
foreach($fdesc_keys as $fdesc_key) {
20+
if(strpos($fdesc_key, $header_prefix) == 0 &&
21+
strpos($fdesc_key, "_name") > 0) {
22+
$key = substr($fdesc_key, 0, count($fdesc_key) - 6);
23+
24+
if (array_key_exists($key."_name", $_POST) && array_key_exists($key."_path",$_POST)) {
25+
$archive_path = $_POST[$key."_archive_path"];
26+
$tmp_name = $_POST[$key."_path"];
27+
$name = $_POST[$key."_name"];
28+
$content_type = $_POST[$key."_content_type"];
29+
$md5 = $_POST[$key."_md5"];
30+
$size = $_POST[$key."_size"];
31+
32+
echo "<tr><td>$archive_path</td><td>$name</td><td>$tmp_name</td><td>$content_type</td><td>$md5</td><td>$size</td>";
33+
}
34+
}
35+
}
36+
37+
echo "</table>";
38+
39+
}else{?>
40+
<h2>Select files to upload</h2>
41+
<form name="upload" method="POST" enctype="multipart/form-data" action="/upload">
42+
<input type="file" name="file1"><br>
43+
<input type="file" name="file2"><br>
44+
<input type="file" name="file3"><br>
45+
<input type="file" name="file4"><br>
46+
<input type="file" name="file5"><br>
47+
<input type="file" name="file6"><br>
48+
<input type="submit" name="submit" value="Upload">
49+
<input type="hidden" name="test" value="value">
50+
</form>
51+
<?}
52+
?>
53+
</body>
54+
</html>

nginx-unzip.conf

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ http {
4141

4242
upload_pass_form_field "^submit$|^description$";
4343

44-
upload_cleanup 400-599;
44+
upload_cleanup 404 500-505;
4545

4646
upload_filter application/zip {
47-
upload_unzip on;
47+
upload_unzip;
48+
}
49+
50+
upload_filter application/java-archive {
51+
upload_unzip;
4852
}
4953
}
5054

nginx.conf

-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ http {
3939
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
4040

4141
upload_pass_form_field "^submit$|^description$";
42-
43-
upload_filter "application/zip" {
44-
unzip on;
45-
}
4642
}
4743

4844
# Pass altered request body to a backend

0 commit comments

Comments
 (0)