|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Issue with cffile & SQL
I am trying to create webmail app.
I have compose.cfm. After the user is finished and submits the data, it stores the message in an Access file. The user can add up to three attachments. I want to be able to insert each attachment file name into 1 Access field (attachments) using commas to seperate the names. Using the #cffile.ClientFileName#.#cffile.ClientFileExt# code, how do I create distinct code for each of the three attachments? <!--- START BY UPLOADING ATTACHMENTS ---> <cfif FORM.attachment1 NEQ ""> <cffile action="upload" destination=#getMailUser.sendAttachmentDirectory# nameConflict="overwrite" fileField="FORM.attachment1"> </cfif> <cfif FORM.attachment2 NEQ ""> <cffile action="upload" destination=#getMailUser.sendAttachmentDirectory# nameConflict="overwrite" fileField="FORM.attachment2"> </cfif> <cfif FORM.attachment3 NEQ ""> <cffile action="upload" destination=#getMailUser.sendAttachmentDirectory# nameConflict="overwrite" fileField="FORM.attachment3"> </cfif> <!--- MAX THREE ATTACHMENTS UPLOADED ---> <!--- BEGIN SQL INSERT INTO STATEMENT FOR SAVING A COPY IN SENT ITEMS FOLDER ---> <cfquery datasource=#DSNwebmail#> INSERT INTO MailMessages (mailid, em_date, from_address, to, cc, bcc, attachmentDirectory, attachment, subject, body, folder) VALUES ( #SESSION.MM_webmail#, '#DateFormat(Now(), "mm/dd/yy")#', '#getMailUser.email#', '#FORM.to#', '#FORM.cc#', '#FORM.bcc#', '#getMailUser.sendAttachmentDirectory#', ' <cfif #FORM.attachment1# NEQ "">#cffile.ClientFileName#.#cffile.ClientFileExt#</cfif> <cfif #FORM.attachment2# NEQ "">, #cffile.ClientFileName#.#cffile.ClientFileExt#, </cfif> <cfif #FORM.attachment3# NEQ "">#cffile.ClientFileName#.#cffile.ClientFileExt#</cfif> ', '#FORM.subject#', '#FORM.body#', 'Sent Items'); </cfquery> |
|
#2
|
|||
|
|||
|
CFFILE action="upload" should allow you specifiy a "fileField" attribute. You should be able to have multiple CFFILE tags, one for each file field name.
However, if you want to store the name of the file in a database after the upload, you'll need to copy each value for the file name to a temporary variable becuase that gets overwritten as each CFFILE tag is processed. Last edited by kiteless : February 5th, 2004 at 06:20 PM. |
|
#3
|
|||
|
|||
|
So, something like this:
<cfparam name="Attach1" default="#cffile.ClientFileName#.#cffile.ClientFileExt#"> In these statements? <cfif FORM.attachment1 NEQ ""> <cfmailparam file="#getMailUser.sendAttachmentDirectory#\#cffile.ClientFileName#.#cffile.ClientFileExt#"> <cfparam name="Attach1" default="#cffile.ClientFileName#.#cffile.ClientFileExt#"> </cfif> <cfif FORM.attachment2 NEQ ""> <cfmailparam file="#getMailUser.sendAttachmentDirectory#\#cffile.ClientFileName#.#cffile.ClientFileExt#"> <cfparam name="Attach2" default="#cffile.ClientFileName#.#cffile.ClientFileExt#"> </cfif> <cfif FORM.attachment3 NEQ ""> <cfmailparam file="#getMailUser.sendAttachmentDirectory#\#cffile.ClientFileName#.#cffile.ClientFileExt#"> <cfparam name="Attach3" default="#cffile.ClientFileName#.#cffile.ClientFileExt#"> </cfif> |
|
#4
|
|||
|
|||
|
Wait... got it....
<cfif FORM.attachment1 NEQ ""> <cffile action="upload" destination=#getMailUser.sendAttachmentDirectory# nameConflict="overwrite" fileField="FORM.attachment1"> <cfparam name="Attach1" default="#cffile.ClientFileName#.#cffile.ClientFileExt#"> <cfelse> <cfparam name="Attach1" default=""> </cfif> Works awesome. Thanks for the tip. |
|
#5
|
|||
|
|||
|
You can clean it up even further by eliminating the <cfelse> and avoiding the NEQ operator:
<cfset attach1=""> <cfset attach2=""> <cfset attach3=""> <cfif not len( form.attachment1 )> <cffile action="upload" destination=#getMailUser.sendAttachmentDirectory# nameConflict="overwrite" fileField="form.attachment1"> <cfset attach1="#cffile.ClientFileName#.#cffile.ClientFileExt#"> </cfif> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Issue with cffile & SQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|