blob: 6d084cacf9ba58d18944aceabcbe283943f5ddcb [file] [log] [blame]
<!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 &quot;image/jpeg&quot; instead of &quot;text/html&quot;
</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">&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Image Example&lt;/title&gt;&lt;/head&gt;&quot;</FONT></B>
web::put <B><FONT COLOR="#BC8F8F">&quot;&lt;body bgcolor=\&quot;#FFFFFF\&quot;&gt;&quot;</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">&quot;&lt;img src=\&quot;[web::cmdurl image]\&quot; width=\&quot;50\&quot; height=\&quot;50\&quot;\&quot;&gt;&lt;br&gt;&quot;</FONT></B>
web::put <B><FONT COLOR="#BC8F8F">&quot;&lt;a href=\&quot;[web::cmdurl default]\&quot;&gt;next&lt;/a&gt;&quot;</FONT></B>
<I><FONT COLOR="#B22222"># properly close html code
</FONT></I> web::put <B><FONT COLOR="#BC8F8F">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</FONT></B>
}
web::command default {
page
}
<I><FONT COLOR="#B22222"># dispatch (see &quot;dispatch_example&quot;)
</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>