In a message dated 9/4/2002 10:08:21 AM Eastern Daylight Time,
[EMAIL PROTECTED] writes:
> Will someone give me a working example of how to upload a file?
First I wrote a proc (below) to drop the path and get the filename by itself.
I'm sure can be tweaked if I were to use string last instead of string
first, but for the most part it works for me. Also I have not tried this on
a non-windows machine so I'm not sure how it accomodates other platforms'
pathing schemas. I'm sure someone can fix it if it doesn't, though :) Since
100% of the users of the applications I write are on windows, it hasn't been
a priority to check that!
At any rate, once you have the file name by itself, you need to access the
uploaded data and copy that to wherever you want to put it. Posted file data
can be accessed through file_control_name.tmpfile. In the example below, the
file upload control on the form is named f.
<snip>
set myfile [dropPathDOS [ns_queryget f]]
#convert spaces in win32 filename to underscore
regsub -all " " $myFile "_" myFile
ns_cp [ns_queryget f.tmpfile] [ns_info pageroot]/my_uploads_folder/$myFile
proc dropPathDOS { filepath } {
#############################################
# #
# Drops the path from a DOS path\file name #
# #
#############################################
set lastSlash 0
while { $lastSlash >= 0 } {
set filepath [string range $filepath [expr $lastSlash + 1] end]
set lastSlash [string first \\ $filepath]
}
return $filepath
}