Lasso Soft Inc. > Home

[amtac_fileuploads]

Linkamtac_fileuploads
AuthorJolle Carlestam
CategoryFile
Version9.x
LicensePublic Domain
Posted11 Feb 2013
Updated11 Feb 2013
More by this author...

Description

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

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

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.

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

}

?>

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft