# Upload test page with progress statistics # # Vlad Seryakov vlad@crystalballinc.com # # Command to perform set cmd [ns_queryget cmd] # Name of current server set server [ns_info server] # In case of very large files and if server set maxupload limit, this # will return temporary file name where all content is spooled set file [ns_conn contentfile] # No query and not empty file means we need to deal with situation when # all content is in the temp file if { $cmd eq "" && $file ne "" } { ns_log notice uploaded into $file, content type = [ns_set iget [ns_conn headers] content-type] file rename -force -- $file /tmp/test set cmd upload } switch -- $cmd { stats { # Discover absolute path to the script set url [ns_normalizepath [file dirname [ns_conn url]]/upload.tcl] set stats [ns_upload_stats $url] ns_log Notice upload.tcl: $url: $stats # Calculate percentage if { $stats ne "" } { foreach { len size } $stats {} set stats [expr {round($len.0*100/$size.0)}] } else { set stats -1 } ns_return 200 text/html $stats } upload { ns_return 200 text/html "Upload completed" } form { ns_return 200 text/html {
File:
} } default { ns_return 200 text/html [subst { Upload Test

Upload test page with progress statistics

Back to example page.
}] } }