1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#!/usr/bin/wapptclsh
#
# This script demonstrates a Wapp application that can accept a file
# upload using <input type="file">
#
package require wapp
proc wapp-default {} {
proc common-header {} {
wapp-content-security-policy {default-src 'self'; img-src 'self' data:}
wapp-trim {
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="%url([wapp-param SCRIPT_NAME]/style.css)" rel="stylesheet">
<title>Wapp File-Upload Demo</title>
</head>
<body>
}
}
proc common-footer {} {
wapp-trim {
</body>
</html>
}
}
proc wapp-default {} {
wapp-content-security-policy {default-src 'self'; img-src 'self' data:}
common-header
wapp-trim {
<h1>Wapp File-Upload Demo</h1>
}
# NB: You must set enctype="multipart/form-data" on your <form> in order
# for file upload to work.
wapp-trim {
<p><form method="POST" enctype="multipart/form-data">
File To Upload: <input type="file" name="file"><br>
<input type="checkbox" name="showenv" value="1">Show CGI Environment<br>
<input type="submit" value="Submit">
</form></p>
<p><a href='%html([wapp-param SCRIPT_NAME])/self'>Show the script
that generates this page</a></p>
}
# Ordinary query parameters come through just like normal
if {[wapp-param showenv 0]} {
wapp-trim {
<h1>Wapp Environment</h1>
<pre>%html([wapp-debug-env])</pre>
}
|
61
62
63
64
65
66
67
68
69
70
71
72
73
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
|
Content:</p>
<blockquote><pre>
%html($content)
</pre></blockquote>
}
}
}
common-footer
}
proc wapp-page-self {} {
wapp-cache-control max-age=3600
common-header
set fd [open [wapp-param SCRIPT_FILENAME] rb]
set script [read $fd]
close $fd
wapp-trim {
</body>
</html>
<h1>Wapp Script That Shows A Copy Of Itself</h1>
<pre>%html($script)</pre>
}
common-footer
}
proc wapp-page-style.css {} {
wapp-mimetype text/css
wapp-cache-control max-age=3600
wapp-trim {
pre {
border: 1px solid black;
padding: 1ex;
}
}
}
wapp-start $argv
|