Skip to content

Commit

Permalink
Improved example script and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
vkholodkov committed Aug 1, 2008
1 parent 36f1afe commit 383e9ea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
45 changes: 24 additions & 21 deletions index.php → example.php
@@ -1,33 +1,37 @@
<?php
$header_prefix = 'file';
$upload_dir = 'upload';
$slots = 6;

?>
<html>
<head>
<title>Test upload</title>
</head>
<body>
<?
if ($_POST){
for ($i=0;$i<=$slots;$i++){
echo "<h2>Uploaded files:</h2>";
echo "<table border=\"2\" cellpadding=\"2\">";

echo "<tr><td>Name</td><td>Location</td><td>Content type</td><td>MD5</td><td>Size</tr>";

for ($i=1;$i<=$slots;$i++){
$key = $header_prefix.$i;
if (array_key_exists($key."_name", $_POST) && array_key_exists($key."_path",$_POST)) {
$tmp_name = $_POST[$key."_path"];
$name = $_POST[$key."_name"];
$newname = $upload_dir."/".$name;
if (rename($tmp_name, $newname)) {
echo "Moved to $upload_dir successfull<br/>\n";
} else {
echo "Failed to move file<br/>\n";
}
}else{
continue;
$content_type = $_POST[$key."_content_type"];
$md5 = $_POST[$key."_md5"];
$size = $_POST[$key."_size"];

echo "<tr><td>$name</td><td>$tmp_name</td><td>$content_type</td><td>$md5</td><td>$size</td>";
}
}
}else{?>

<html>
<head>
<title>Test upload</title>
</head>
<body>
echo "</table>";

}else{?>
<h2>Select files to upload</h2>
<form name="upload" method="POST" enctype="multipart/form-data" action="/doupload">
<form name="upload" method="POST" enctype="multipart/form-data" action="/upload">
<input type="file" name="file1"><br>
<input type="file" name="file2"><br>
<input type="file" name="file3"><br>
Expand All @@ -37,8 +41,7 @@
<input type="submit" name="submit" value="Upload">
<input type="hidden" name="test" value="value">
</form>
<?}
?>
</body>
</html>

<?}
?>
25 changes: 22 additions & 3 deletions nginx.conf
Expand Up @@ -14,15 +14,34 @@ http {
default_type application/octet-stream;

server {
client_max_body_size 100m;
listen 80;
server_name localhost;
client_max_body_size 100m;

# Upload form should be submitted to this location
location /upload {
# Pass altered request body to this location
upload_pass /test;
upload_store /tmp;

# Store files to this directory
# The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
upload_store /tmp 1;

# Allow uploaded files to be read only by user
upload_store_access user:r;

# Set specified fields in request body
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;

# Inform backend about hash and size of a file
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;

upload_pass_form_field "^submit$|^description$";
}

# Pass altered request body to a backend
location /test {
proxy_pass http://localhost:8080;
}
Expand Down

0 comments on commit 383e9ea

Please sign in to comment.