Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading Multiple Files with CFFILE

Status
Not open for further replies.

infocusweb

Technical User
Jan 8, 2001
17
0
0
US
hey folks - here is my dilemma - I can upload multiple files to a directory but I can't add both filenames to the database. here's what's going on:

ImageONE: <INPUT NAME=&quot;FileName1&quot; SIZE=30 TYPE=FILE required=yes message=&quot;please select a small image&quot;>
<BR>
ImageTWO: <INPUT NAME=&quot;FileName2&quot; SIZE=30 TYPE=FILE required=yes message=&quot;please select a large image&quot;>

<cfif IsDefined(&quot;filename1&quot;)>
<cftry>

<CFFILE DESTINATION=&quot;user\placewherephotosarestored\photos\&quot;
ACTION=&quot;UPLOAD&quot;
NAMECONFLICT=&quot;OVERWRITE&quot;
MODE=&quot;666&quot;
FILEFIELD=&quot;filename1&quot;>
<cfcatch type=&quot;any&quot;>
</cfcatch>
</cftry>
</cfif>

Which seems to work and but:

<cfquery datsource=datasource>
INSERT INTO Photos
(ImageONE,ImageTWO)
VALUES
('#File.ClientFileName#.#File.ClientFileExt#,'#File.ClientFileName#.#File.ClientFileExt#')
</cfquery>

ClientfileName Attibute can't differentiate between ImageONE and ImageTWO so it enters the the first value into both fields.

Can anyone help me out with this. Thanks!

http//
 
I don't see the code that uploads filename2. Could you post all of your code that handles the uploaded files?


Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
Can you not upload the images in their own records? You are tring to insert multiple images to one recordset. Best way is to have 2 tables table 1 is what the image is attached too and it has a autonumber or some type of PKID.
Table 2 is for the images associate the images to the other table by the PKID.

Upload

<cfquery>
INSERT INTO TABLE (PKID, Image) VALUES (PKID, '#file.clientfile#'
</cfquery>

- hope this helps

Wes
 
Analyze your INSERT query variable names:
ImageOne=#File.ClientFileName#.#File.ClientFileExt#
ImageTwo=#File.ClientFileName#.#File.ClientFileExt#

The var names are the same for ImageOne AND ImageTwo. Doesn't it make sense that cf server must evaluate the variables with the same value (unless of course you were looping through a struct, array, list etc).

What you will probably want to do is set a local var for each file variable.

ex:

<CFFILE DESTINATION=&quot;user\placewherephotosarestored\photos\&quot;
ACTION=&quot;UPLOAD&quot;
NAMECONFLICT=&quot;OVERWRITE&quot;
MODE=&quot;666&quot;
FILEFIELD=&quot;filename1&quot;> <!--- remember to scope your vars --->
<cfcatch type=&quot;any&quot;>
</cfcatch>
</cftry>
</cfif>

<!--- Set local var for the first file name --->
<cfset locFileName1=file.clientfile>

<CFFILE DESTINATION=&quot;user\placewherephotosarestored\photos\&quot;
ACTION=&quot;UPLOAD&quot;
NAMECONFLICT=&quot;OVERWRITE&quot;
MODE=&quot;666&quot;
FILEFIELD=&quot;form.filename2&quot;> <!--- remember to scope your vars --->
<cfcatch type=&quot;any&quot;>
</cfcatch>
</cftry>
</cfif>

<!--- Set local var for the second file name --->
<cfset locFileName2=file.clientfile>

<!--- Insert file names into db --->
<cfquery datsource=datasource>
INSERT INTO Photos
(ImageONE,ImageTWO)
VALUES
('#locFileName1#','#locFileName2#')
</cfquery>

Note that for each cffile process, any previous #file# that existed will be overwritten with the newest cffile process.

What we did here is trap the #file# before running the next cffile.
 
faq232-2211

Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top