Learning ColdFusion 8: CFThread Part III - Set It And Forget It

<!--- Kill extra output. --->
<cfsilent>
 
	<!---
		Param the FORM variable that will hold our photo urls.
		Remember, each URL is on its own line (separrated by
		line returns).
	--->
	<cfparam
		name="FORM.photo_url"
		type="string"
		default=""
		/>
 
 
	<!---
		Get a value for the time at which the page started
		processing. We will need this to see how long it takes
		the page to run.
	--->
	<cfset intStartTime = GetTickCount() />
 
 
	<!--- Trim the form field. --->
	<cfset FORM.photo_url = FORM.photo_url.Trim() />
 
 
	<!---
		Check to see if the form has been submitted. For
		this demo, we will know this if there is a value
		in the form field.
	--->
	<cfif Len( FORM.photo_url )>
 
		<!---
			Loop over the URLs. We can treat the text area
			as if it were a list of URLs that is using the
			line break, line return as the list delimiter.
		--->
		<cfloop
			index="strURL"
			list="#FORM.photo_url#"
			delimiters="#Chr( 13 )##Chr( 10 )#">
 
			<!---
				Now that we have our individual URL, let's
				grab the photo binary using CFHttp and store
				it directly into a file on the server.
			--->
			<cfhttp
				url="#strURL#"
				method="GET"
				getasbinary="yes"
				path="#ExpandPath( './data/' )#"
				file="#GetFileFromPath( strURL )#"
				/>
 
		</cfloop>
 
	</cfif>
 
</cfsilent>
 
<cfoutput>
 
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html>
	<head>
		<title>ColdFusion 8 - CFThread Demo</title>
	</head>
	<body>
 
		<h2>
			Flickr.com Photo Download
		</h2>
 
 
		<!---
			Check to see if the form as been submitted. For
			this demo, we will know this if there is a value
			in the form field.
		--->
		<cfif NOT Len( FORM.photo_url )>
 
			<p>
				Please enter photo URLs that you would like to
				download. Each URL should be on a single line of
				the following text area.
			</p>
 
			<form
				action="#CGI.script_name#"
				method="post">
 
				<p>
					<textarea
						name="photo_url"
						cols="70"
						rows="20"
						>#FORM.photo_url#</textarea>
				</p>
 
				<p>
					<input type="submit" value="Download Now" />
				</p>
 
			</form>
 
		<cfelse>
 
			<p>
				Your photos have been downloaded!
			</p>
 
		</cfif>
 
 
		<!--- Output how long it took the page to run. --->
		<p>
			Page ran in:
			#NumberFormat(
			((GetTickCount() - intStartTime) / 1000),
			",.00"
			)#
			seconds.
		</p>
 
	</body>
	</html>
 
</cfoutput>

For Cut-and-Paste