Hi everyone,
I need to assistance with uploading multiple files. I have a classifieds
section with a form below that when submitted uploads pictures and makes a
record in the database. That works but only if I use all four files. If I
submit no files it throws an error which I expect. For the life of me I am
trying to figure out a way to detect whether a field has a file and upload.
Thank you.
The form page.
<cfparam name="classphotoaction" default="" />
<cfparam name="adid" default="testing" />
<cfif classphotoaction eq "create">
<cfinvoke component="/renocfc/classifiedsphoto"
method="createclassifiedsphotos">
<cfinvokeargument name="adid" value="#adid#" />
<cfloop index="i" from="1" to="4">
<cfset photo = "photo" & #i# />
<cfinvokeargument name="#photo#" value="#photo#" />
</cfloop>
</cfinvoke>
</cfif>
<form action="#cgi.script_name#" method="post" enctype="multipart/form-data">
<cfloop index="i" from="1" to="4">
<label for="photo#i#">Photo #i#:</label>
<input id="photo#i#" name="photo#i#" type="file" /><br />
</cfloop>
<input id="submit" name="submit" type="submit" value="Add Photo(s)
>>>" />
<input id="classphotoaction" name="classphotoaction" type="hidden"
value="create" />
</form>
The function.
<cffunction name="createclassifiedsphotos" access="public" returntype="void">
<cfargument name="adid" type="any" required="yes" />
<cfset var createclassifiedsphotos = "" />
<cfloop index="i" from="1" to="4">
<cfset photofile = "photo" & #i# />
<cffile action="upload" filefield="#photofile#"
destination="\classifiedsphotos" nameconflict="makeunique" />
<cfset photo = "#file.clientfile#" />
<cfset resize = imagenew("\classifiedsphotos\#photo#") />
<cfset imageresize(resize,"250","") />
<cfimage source="#resize#" action="write"
destination="\classifiedsphotos\#photo#" overwrite="yes">
<cfquery name="createclassifiedsphoto" datasource="">
insert into
classifieds_photos (
photofile,
adid
)
values (
'#photo#',
'#arguments.adid#'
);
</cfquery>
</cfloop>
<cfreturn />
</cffunction>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648
Archive:
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:3104
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15