| <!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN"> |
| <HTML> |
| <HEAD> |
| <TITLE>image</TITLE> |
| </HEAD> |
| <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#1F00FF" ALINK="#FF0000" VLINK="#9900DD"> |
| <A NAME="top"> |
| <A NAME="file1"> |
| <H1>image.ws3</H1> |
| |
| <PRE> |
| <I><FONT COLOR="#B22222"># gif sample - return a image/gif instead of text/html |
| </FONT></I><I><FONT COLOR="#B22222"># |
| </FONT></I><I><FONT COLOR="#B22222"># this example demonstrates how to use cookies with websh3 |
| </FONT></I><I><FONT COLOR="#B22222"># |
| </FONT></I> |
| web::command <B><FONT COLOR="#A020F0">image</FONT></B> { |
| |
| <B><FONT COLOR="#A020F0">set</FONT></B> nr [<B><FONT COLOR="#A020F0">format</FONT></B> %2.2d [<B><FONT COLOR="#A020F0">expr</FONT></B> int(rand() * 13)]] |
| |
| <I><FONT COLOR="#B22222"># open a file (JPEG is a binary format) |
| </FONT></I> <B><FONT COLOR="#A020F0">set</FONT></B> fh [<B><FONT COLOR="#A020F0">open</FONT></B> [<B><FONT COLOR="#A020F0">file</FONT></B> <B><FONT COLOR="#A020F0">join</FONT></B> [web::config document_root] websh images memory $<FONT COLOR="#B8860B">nr</FONT>.jpg] r] |
| <B><FONT COLOR="#A020F0">fconfigure</FONT></B> $<FONT COLOR="#B8860B">fh</FONT> -translation binary |
| <B><FONT COLOR="#A020F0">set</FONT></B> img [<B><FONT COLOR="#A020F0">read</FONT></B> $<FONT COLOR="#B8860B">fh</FONT>] |
| close $<FONT COLOR="#B8860B">fh</FONT> |
| |
| <I><FONT COLOR="#B22222"># set HTTP header to "image/jpeg" instead of "text/html" |
| </FONT></I> web::response -<B><FONT COLOR="#A020F0">set</FONT></B> Content-Type <B><FONT COLOR="#A020F0">image</FONT></B>/jpeg |
| |
| <I><FONT COLOR="#B22222"># because we return a img, change to binary again |
| </FONT></I> <B><FONT COLOR="#A020F0">fconfigure</FONT></B> [web::response] -translation binary |
| |
| <I><FONT COLOR="#B22222"># output |
| </FONT></I> web::put $<FONT COLOR="#B8860B">img</FONT> |
| } |
| |
| <I><FONT COLOR="#B22222"># produce the page of this sample application |
| </FONT></I><B><FONT COLOR="#A020F0">proc</FONT></B> <B><FONT COLOR="#0000FF">page</FONT></B> {<FONT COLOR="#B8860B"></FONT>} { |
| |
| web::put <B><FONT COLOR="#BC8F8F">"<html><head><title>Image Example</title></head>"</FONT></B> |
| web::put <B><FONT COLOR="#BC8F8F">"<body bgcolor=\"#FFFFFF\">"</FONT></B> |
| |
| <I><FONT COLOR="#B22222"># the images: returned by the same app, but a different command |
| </FONT></I> web::put <B><FONT COLOR="#BC8F8F">"<img src=\"[web::cmdurl image]\" width=\"50\" height=\"50\"\"><br>"</FONT></B> |
| web::put <B><FONT COLOR="#BC8F8F">"<a href=\"[web::cmdurl default]\">next</a>"</FONT></B> |
| <I><FONT COLOR="#B22222"># properly close html code |
| </FONT></I> web::put <B><FONT COLOR="#BC8F8F">"</body></html>"</FONT></B> |
| } |
| |
| web::command default { |
| |
| page |
| } |
| |
| <I><FONT COLOR="#B22222"># dispatch (see "dispatch_example") |
| </FONT></I>web::dispatch |
| </PRE> |
| <HR> |
| <ADDRESS>Generated by <A HREF="http://www.iki.fi/~mtr/genscript/">GNU enscript 1.6.3</A>.</ADDRESS> |
| </BODY> |
| </HTML> |