Forum OpenACS Development: Re: FS pkg: Upload multiple files

Posted by Antonio Pisano on
Dear Iuri,

I could make a toy example for you. Create a page in %server-root%/www/test-form.tcl with this code:

ad_page_contract {
} {

set existing {}
foreach f ${upload_file.tmpfile} {
lappend existing [file exists $f]
ns_return 200 text/html "$upload_file -- ${upload_file.tmpfile} -- $existing -- ${upload_file.content-type}"

Then from the /ds/shell test it like this:

set files {
{data aaa filename test.html fieldname upload_file}
{data bbb filename test2.txt fieldname upload_file}
array set r [util::http::post -url -files $files]

set r(page)

As you can see, multiple file uploads will make each variable a list you can loop through in respective order.

Hope this helps


Posted by Iuri Sampaio on
Thanks a lot Pisano!
You helped me to realize that there's nothing new!

"var.var" is a simple thing and it should the treated as a list. The usage of foreach statement is enough to iterate and catch all multiple values within the variable.

The key was that I should have used the entire name explicitly, as the variable's name (i.e. upload_file.tmpfile).

I was killing myself because I was trying to reach the values,
using only the first part of its name, as in: $upload_file and $upload_file(tmp file). Then, I got lost writing more trash code related to TCL array and etc

Thanks again and Best wishes,