# gif sample - return a image/gif instead of text/html # # this example demonstrates how to use cookies with websh3 # web::command image { set nr [format %2.2d [expr int(rand() * 13)]] # open a file (JPEG is a binary format) set fh [open [file join [web::config document_root] websh images memory $nr.jpg] r] fconfigure $fh -translation binary set img [read $fh] close $fh # set HTTP header to "image/jpeg" instead of "text/html" web::response -set Content-Type image/jpeg # because we return a img, change to binary again fconfigure [web::response] -translation binary # output web::put $img } # produce the page of this sample application proc page {} { web::put "Image Example" web::put "" # the images: returned by the same app, but a different command web::put "
" web::put "next" # properly close html code web::put "" } web::command default { page } # dispatch (see "dispatch_example") web::dispatch