Difference between revisions of "Ns returnfile"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | + | ns_returnfile 200 "application/zip" $filepath | |
ns_returnfile 200 [ns_guesstype $file] $filepath | ns_returnfile 200 [ns_guesstype $file] $filepath | ||
==== Caveat programmor ==== | ==== Caveat programmor ==== | ||
− | ns_returnfile uses [[fastpath]] internally, so care should be taken when using it to return dynamically generated files. A better practice if dealing with dynamic data in the filesystem would probably be to use [[ | + | ns_returnfile uses [[fastpath]] internally, so care should be taken when using it to return dynamically generated files. A better practice if dealing with dynamic data in the filesystem would probably be to use [[ns_return]] instead. For example: |
− | + | set fd [open $myfile] | |
+ | ns_unlink $myfile; # So that nothing else can access the file from the filesystem | ||
+ | ns_return 200 [ns_guesstype $myfile] [read $fd] | ||
+ | close $fd | ||
==== Want to name the file returned? ==== | ==== Want to name the file returned? ==== | ||
ns_set update [ns_conn outputheaders] content-disposition "attachment; filename=1.abc" | ns_set update [ns_conn outputheaders] content-disposition "attachment; filename=1.abc" |
Revision as of 13:24, 19 August 2008
ns_returnfile 200 "application/zip" $filepath
ns_returnfile 200 [ns_guesstype $file] $filepath
Caveat programmor
ns_returnfile uses fastpath internally, so care should be taken when using it to return dynamically generated files. A better practice if dealing with dynamic data in the filesystem would probably be to use ns_return instead. For example:
set fd [open $myfile] ns_unlink $myfile; # So that nothing else can access the file from the filesystem ns_return 200 [ns_guesstype $myfile] [read $fd] close $fd
Want to name the file returned?
ns_set update [ns_conn outputheaders] content-disposition "attachment; filename=1.abc"