7 <form action=/cgi-bin/post_upload.cgi method=post enctype=multipart/form-data>
8 File to upload: <input type=file name=file1> <input type=submit>
17 # -----------------------------29995809218093749221856446032^M
18 # Content-Disposition: form-data; name="file1"; filename="..."^M
19 # Content-Type: application/octet-stream^M
20 # ^M <--------- headers end with empty line
24 # ^M <--------- extra empty line
25 # -----------------------------29995809218093749221856446032--^M
27 # Beware: bashism $'\r' is used to handle ^M
31 # CGI output must start with at least empty line (or headers)
38 delim_line="${delim_line}--"$'\r'
40 while read -r line; do
41 test "$line" = '' && break
42 test "$line" = $'\r' && break
45 # This will not work well for binary files: bash 3.2 is upset
46 # by reading NUL bytes and loses chunks of data.
47 # If you are not bothered by having junk appended to the uploaded file,
48 # consider using simple "cat >file" instead of the entire
51 while read -r line; do
53 while test "$line" = $'\r'; do
55 test "$line" = "$delim_line" && {
56 # Aha! Empty line + delimiter! All done
60 File upload has been accepted
64 # Empty line + NOT delimiter. Save empty line,
65 # and go check next line
66 printf "%s\n" $'\r' -vC >&3
68 # Not empty line - just save
69 printf "%s\n" "$line" -vC >&3
75 File upload was not terminated with '$delim_line' - ??!