#!/pkg/gnu/bin/gawk -f BEGIN { print "Content-type: text/html" print "" while (getline) print > "upfile.out" exit if (0) showfile() else { getfile() print "" } } function showfile() { print "
"
  while (getline) { 
    # note that you can't always print $0 because binary chars can mess connection
    print length($0)
    # print $0 # , length($0)
    # print $0 > "/tmp/upfile.tmp"
  }
  # close("/tmp/upfile.tmp")
  # system("od -x /tmp/upfile.tmp")
}

function getfile(  delim) {
  getline delim
  while (getline) {
    if ($0 ~ /Content-Disposition/) {
      getline # image type
      getline # empty
      while (getline) {
        if ($0 ~ delim) break
	else print > "uploadedfile"
      }
    }
  }
}