Hey all, I'm using the following script to allow users to upload 3 images. It
seems to work fairly well, but I have 2 issues.
1. It errors unless a user uploads all 3 images. I'd like to give them the
option of only uploading 1 or 2 images.
2. I have a hidden form variable called IsPrimary that should set the image in
the first upload field to "Yes" and the other 2 to "No" (the IsPrimary image is
the one that shows up in searches, etc.) But with this script, they're all
being set to "Yes"
Any ideas on how to solve these 2 issues?
Thanks
Rick
--------------------------------------------------------
<cfparam name="SESSION.Auth.UserID" default="">
<cfparam name="FORM.CatID" default="">
<cfparam name="FORM.Category" default="">
<cfparam name="FORM.Designer" default="">
<cfparam name="FORM.Model" default="">
<cfparam name="FORM.Color" default="">
<cfparam name="FORM.Size" default="">
<cfparam name="FORM.Price" default="">
<cfparam name="FORM.Material" default="">
<cfparam name="FORM.Description" default="">
<cfparam name="FORM.IsPrimary" default="0">
<cftransaction>
<cfquery name="Product" datasource="DB">
SET NOCOUNT ON;
INSERT INTO Products (CatID, UserID, Designer, Model, Color, Price,
Material, Description, Status)
VALUES ('#Trim(FORM.CatID)#',
'#Trim(SESSION.Auth.UserID)#',
'#Trim(FORM.Designer)#',
'#Trim(FORM.Model)#',
'#Trim(FORM.Color)#',
'#Trim(FORM.Price)#',
'#Trim(FORM.Material)#',
'#Trim(FORM.Description)#',
'Pending');
SELECT @@identity AS ProdID FROM Products;
</cfquery>
<!--- Accept the file upload --->
<cfloop from="1" to="3" index="i">
<cffile
action="upload"
filefield="file#i#"
result="cffile.file#i#"
destination="#ExpandPath('users/uploads/')#"
nameconflict="makeunique"
accept="image/jpg, image/JPG, image/jpeg, image/JPEG, image/gif, image/GIF,
image/pjpeg, image/pjpg">
<!--- Resize, rename and set the quality of the image uploaded with
cfx_openimage --->
<cfx_openimage
action="iml"
name="qimages"
file="#ExpandPath('users/uploads/')##cffile['file'&i].serverFile#"
commands="
setjpegdpi 72
setquality 100
setimage large=original
setimage thumb=original
## resize if either width or height is greater than 500
useimage large
resizeif 500,400
write #ExpandPath('users/uploads/'&cffile['file'&i].serverFileName&'.jpg')#
## resize if either width or height is greater than 100
useimage thumb
resizeif 100,75
write #ExpandPath('users/uploads/th_'&cffile['file'&i].serverFileName&'.jpg')#
">
<!--- Upload to database --->
<cfquery datasource="wioDB">
INSERT INTO Images (ProdID, Image, IsPrimary)
VALUES (#Product.ProdID#,'#cffile['file'&i].serverFile# ',
'#FORM.IsPrimary#')
</cfquery>
</cfloop>
</cftransaction>
<cflocation url="review.cfm?ProdID=#Product.ProdID#">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Deploy Web Applications Quickly across the enterprise with ColdFusion MX7 &
Flex 2.
Free Trial
http://www.adobe.com/products/coldfusion/flex2/
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:271126
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4