[amtac_fileuploads]

Description

Link: [amtac_fileuploads]
Author: Jolle Carlestam
Category: File
Version: 9.x
License: Public Domain
Posted: Nov. 06, 2011
Updated: Nov. 06, 2011
More by this author...

Wrapper around Lasso 9s upload methods that makes it easy and convinient to process uploaded files.

Parameters

none


Sample Usage

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 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')
						

Source Code

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?LassoScript
/**!
amtac_fileuploads
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 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')

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
		do {
			#lcount += 1
			#fup_tmp = map
			with upl in #fup
			do {
				#fup_tmp -> insert(#upl -> first = #upl->second)
			}
			.'fileinfo' -> insert(#lcount = #fup_tmp)
			#lcount >= #_count ? loop_abort
		}
		.'size' = .'fileinfo' -> size

	} // 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'))
		}
	}

}

?>

 

Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net