Wapp

Check-in [cdd099b81e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a "self" page to the fileupload.tcl demo.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cdd099b81ebc1d13dba0e6b59e41d86463754b3fbd8880d6c5dbadea08168470
User & Date: drh 2019-04-23 19:35:00
Context
2019-04-23
19:52
Improvements to the tableajax01.tcl example. check-in: ab89ab225b user: drh tags: trunk
19:35
Add a "self" page to the fileupload.tcl demo. check-in: cdd099b81e user: drh tags: trunk
18:04
Fix a typo in the quickref.md document. check-in: 713d5e77fc user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to examples/fileupload.tcl.

     1      1   #!/usr/bin/wapptclsh
     2      2   #
     3      3   # This script demonstrates a Wapp application that can accept a file
     4      4   # upload using <input type="file">
     5      5   #
     6      6   package require wapp
     7         -proc wapp-default {} {
     8         -  wapp-content-security-policy {default-src 'self'; img-src 'self' data:}
            7  +proc common-header {} {
     9      8     wapp-trim {
    10      9       <html>
    11     10       <head>
    12     11       <meta name="viewport" content="width=device-width, initial-scale=1.0">
    13     12       <meta http-equiv="content-type" content="text/html; charset=UTF-8">
           13  +    <link href="%url([wapp-param SCRIPT_NAME]/style.css)" rel="stylesheet">
    14     14       <title>Wapp File-Upload Demo</title>
    15     15       </head>
    16     16       <body>
           17  +  }
           18  +}
           19  +proc common-footer {} {
           20  +  wapp-trim {
           21  +    </body>
           22  +    </html>
           23  +  }
           24  +}
           25  +proc wapp-default {} {
           26  +  wapp-content-security-policy {default-src 'self'; img-src 'self' data:}
           27  +  common-header
           28  +  wapp-trim {
    17     29       <h1>Wapp File-Upload Demo</h1>
    18     30     }
    19     31     # NB:  You must set enctype="multipart/form-data" on your <form> in order
    20     32     # for file upload to work.
    21     33     wapp-trim {
    22     34       <p><form method="POST" enctype="multipart/form-data">
    23     35       File To Upload: <input type="file" name="file"><br>
    24     36       <input type="checkbox" name="showenv" value="1">Show CGI Environment<br>
    25     37       <input type="submit" value="Submit">
    26     38       </form></p>
           39  +    <p><a href='%html([wapp-param SCRIPT_NAME])/self'>Show the script
           40  +    that generates this page</a></p>
    27     41     }
    28     42     # Ordinary query parameters come through just like normal
    29     43     if {[wapp-param showenv 0]} {
    30     44       wapp-trim {
    31     45         <h1>Wapp Environment</h1>
    32     46         <pre>%html([wapp-debug-env])</pre>
    33     47       }
................................................................................
    61     75           Content:</p>
    62     76           <blockquote><pre>
    63     77           %html($content)
    64     78           </pre></blockquote>
    65     79         }
    66     80       }
    67     81     }
           82  +  common-footer
           83  +}
           84  +proc wapp-page-self {} {
           85  +  wapp-cache-control max-age=3600
           86  +  common-header
           87  +  set fd [open [wapp-param SCRIPT_FILENAME] rb]
           88  +  set script [read $fd]
           89  +  close $fd
           90  +  wapp-trim {
           91  +    <h1>Wapp Script That Shows A Copy Of Itself</h1>
           92  +    <pre>%html($script)</pre>
           93  +  }
           94  +  common-footer
           95  +}
           96  +proc wapp-page-style.css {} {
           97  +  wapp-mimetype text/css
           98  +  wapp-cache-control max-age=3600
    68     99     wapp-trim {
    69         -    </body>
    70         -    </html>
          100  +    pre {
          101  +       border: 1px solid black;
          102  +       padding: 1ex;
          103  +    }
    71    104     }
    72    105   }
    73    106   wapp-start $argv