#include "CGI.h" #include "Escape.h" #include "FileStream.h" /* Ultra-short-n-simple demo of file upload */ int main() { CGI cgi ; cgi["file"] = new form_longfile() ; String Source("Source") ; cgi["display"] = new form_radio(Source, " ") ; cgi["display"]["source"] = "Source" ; cgi["display"]["render"] = "Rendered HTML" ; cgi.form() ; // read the input! /* Print a mini-form inviting user to upload a file */ cout << "Content-type: text/html\n\n" "
Use the form to upload a file from your local system. " "When you upload an HTML file, you can either display source " "or render it (for other file types, the Display option has " "no effect). Note that if you render an HTML file it is " "not parsed, so the file contents should " "be limited to body text or the results may be unpredictable. " "Do not send files containing confidential information!
" << cgi.start("filedemo.cgi", "POST", "multipart/form-data") << cgi.submit("Upload") << cgi.render("file") << " Display as: " << cgi.render("display") << cgi.end() << "Sorry, your Browser doesn't support HTTP File Upload.
" ; else if ( ! cgi["file"] ) cout << "Didn't get anything - please try again." ; else { cout << "" << html_escape(cgi["file"].as_longtext()) << "" ; else { cout << "
Non-text file not displayed in HTML page." ; } } cout << "
" "The C++ source for this " "demo program is here.