REBOL [ title: "File Download CGI" date: 10-Aug-2010 file: %file-download-cgi.r author: Nick Antonaccio purpose: { Push file download from web server to browser. } ] #! ./rebol -cs REBOL [title: "CGI File Downloader"] submitted: decode-cgi system/options/cgi/query-string root-path: "/home/path" if ((submitted/2 = none) or (submitted/4 = none)) [ print "content-type: text/html^/" print ["W A R N I N G - "] print ["Private Server, Login Required:"

] print [
] print [" Username: "

] print [" Password: "

] print [" File: "

] print [] print [

] print [] print [
] quit ] username: submitted/2 password: submitted/4 either (username = "user") and (password = "pass") [ ; if user/pass is ok, go on ][ print "content-type: text/html^/" print "Incorrect Username/Password." quit ] print rejoin [ "Content-Type: application/x-unknown" newline "Content-Length: " (size? to-file join root-path submitted/6) newline "Content-Disposition: attachment; filename=" (second split-path to-file submitted/6) newline ] data: read/binary to-file join root-path submitted/6 data-length: size? to-file join root-path submitted/6 write-io system/ports/output data data-length