Link | amtac_fileuploads |
Author | Jolle Carlestam |
Category | File |
Version | 9.x |
License | Public Domain |
Posted | 11 Feb 2013 |
Updated | 11 Feb 2013 |
More by this author... |
Wrapper around Lasso 9s upload methods that makes it easy and convenient to process uploaded files.
var(myfile = amtac_fileuploads(1)) // the integer is optional and will if provided restrict the method to the n:th count of uploaded file $myfile -> size // how many files that were uploaded or handled by the type $myfile -> contenttype // or $myfile -> contenttype(n) when targeting the n:th file // for example image/jpeg $myfile -> fieldname // $myfile -> fieldname(n) $myfile -> filesize // $myfile -> filesize(n) $myfile -> filename // $myfile -> filename(n) $myfile -> tmpfilename // $myfile -> tmpfilename(n) $myfile -> suffix // $myfile -> suffix(n) $myfile -> save('/path/to/file/filename.sfx') or $myfile -> save('/path/to/file/filename.sfx', -overwrite, -count = n) An actual file can also be retrieved as a file object from amtac_fileuploads using $myfile -> file or $myfile -> file(n) Short hand examples amtac_fileuploads -> file // will return the uploaded file as a file object amtac_fileuploads -> save('/path/to/file/filename.sfx')
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
size // how many files that where uploaded or handled by the type $myfile -> contenttype // or $myfile -> contenttype(n) when targeting the n:th file // for example image/jpeg $myfile -> fieldname // $myfile -> fieldname(n) $myfile -> filesize // $myfile -> filesize(n) $myfile -> filename // $myfile -> filename(n) $myfile -> tmpfilename // $myfile -> tmpfilename(n) $myfile -> suffix // $myfile -> suffix(n) $myfile -> save('/path/to/file/filename.sfx') or $myfile -> save('/path/to/file/filename.sfx', -overwrite, -count = n) An actual file can also be retrieved as a file object from amtac_fileuploads using $myfile -> file or $myfile -> file(n) Short hand examples amtac_fileuploads -> file // will return the uploaded file as a file object amtac_fileuploads -> save('/path/to/file/filename.sfx') 2012-07-31 JC Corrected the abortion of the with loop when type is called for only one 2011-10-24 JC First version */ define amtac_fileuploads => type { data private fileinfo = map data private size = 0 public oncreate(count::integer = -1) => { local(fup_tmp = map) local(fups = web_request -> fileuploads) local(_count = #count > 0 ? #count | #fups -> size) local(lcount = 0) with fup in #fups where #lcount < #_count do { #lcount += 1 #fup_tmp = map with upl in #fup do { #fup_tmp -> insert(#upl -> first = #upl->second) } .'fileinfo' -> insert(#lcount = #fup_tmp) } .'size' = .'fileinfo' -> size //stdoutnl('amtac_fileuploads ' + .'size') //stdoutnl('amtac_fileuploads ' + .'fileinfo') } // oncreate public size() => .'size' public contenttype(count::integer = 1) => { if(#count <= .'size') => { return .'fileinfo' -> find(#count) -> find('contenttype') } } public fieldname(count::integer = 1) => { if(#count <= .'size') => { return .'fileinfo' -> find(#count) -> find('fieldname') } } public filesize(count::integer = 1) => { if(#count <= .'size') => { return .'fileinfo' -> find(#count) -> find('filesize') } } public tmpfilename(count::integer = 1) => { if(#count <= .'size') => { return .'fileinfo' -> find(#count) -> find('tmpfilename') } } public filename(count::integer = 1) => { if(#count <= .'size') => { return .'fileinfo' -> find(#count) -> find('filename') } } public suffix(count::integer = 1) => { if(#count <= .'size') => { return .'fileinfo' -> find(#count) -> find('filename') -> split('.') -> last } } public save(path::string, overwrite::boolean = false, count::integer = 1) => { if(#count <= .'size') => { file(.'fileinfo' -> find(#count) -> find('tmpfilename')) -> copyto(#path, #overwrite) } } public save(path::string, -overwrite::boolean = false, -count::integer = 1) => .save(#path, #overwrite, #count) public file(count::integer = 1) => { if(#count <= .'size') => { return file(.'fileinfo' -> find(#count) -> find('tmpfilename')) } } } ?>
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft