473,416 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

upload multiple files like gmail problem.

769 512MB
Hey Everyone,

Well this is my first time asking a question on here so please forgive me if i post
my question in the wrong section.

What i am trying to do is upload multiple files like gmail does. I found a script that does this on easycfm.com (Topic 13543).

But anyway when i try to upload multiple files it will create multiple records in my database (like it should), but it wont upload multiple files. What ever file i choose to upload first it will put in all the records added instead of each record having a different name.However,when i go to the destination of where the files go are suppose to go you will see all the files i uploaded,but in my database it has each record having the same name.

For example
if i upload 2 files. file one is called 1.txt and file two is called 2.txt. Instead of the first record being called1.txt and the other record being called 2.txt it will make both records have the file name as 1.txt. but in my destination folder it will have 1.txt and 2.txt

the only problem i can think of is. In the example there is no stored procedure an well i added my stored procedure into there action page because it will not insert anything into my database without the stored procedure.

here is what my stored procedure looks like (it is below on my action page as well).
Expand|Select|Wrap|Line Numbers
  1.  <cfquery name="attachment" datasource="CustomerSupport">
  2.     exec usp_CS_Insertattachments
  3.    '#Form.ID#','#Form.serialnum#','#Form.attachdescrip#','#Form.attachment1#',
  4. '#Form.fk_addedBy#','#Form.date_added#'
  5. </cfquery>
  6.  

But here is the full code

javascript that lets you upload multiple files

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.      var upload_number = 2;
  3.      function addFileInput()
  4.      {
  5.      var d = document.createElement("div");
  6.      var file = document.createElement("input");
  7.      file.setAttribute("type", "file");
  8.      file.setAttribute("name", "attachment"+upload_number);
  9.      d.appendChild(file);
  10.      document.getElementById("moreUploads").appendChild(d);
  11.      document.getElementById("totalAttachments").value = upload_number;
  12.      upload_number++;
  13.      }
  14. </script>
  15.  
here is the upload page

[HTML]<form action="userform.cfm" id="userForm" name="userForm" method="POST"
enctype="multipart/form-data">
<input type="file" name="attachment1" id="attachment" value="#attachment_ID_counter#"
onchange="document.getElementById('moreUploadsLink ').style.display = 'block';" />
<div id="moreUploads"></div>
<div id="moreUploadsLink" style="display:none;">
<input type="button" value="Attach another file"
onclick="javascript:addFileInput();" >
</div>
<input type="hidden" id="totalAttachments" name="totalAttachments" value="1">
<input type="submit" class="officalsubmit" value="submit" name="submit"
onClick="return validate_form();">
</form>
[/HTML]


here is my action page

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="counter">
  5.       verify the form field exists 
  6.      <cfif structKeyExists(FORM, "attachment"& counter)>
  7.            try and upload it ...
  8.           <cffile action="upload" fileField="attachment#counter#" destination=
  9. "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  10.               <cfquery name="attachment" datasource="CustomerSupport">
  11.     exec usp_CS_Insertattachments
  12.    '#Form.ID#','#Form.serialnum#','#Form.attachdescrip#','#Form.attachment1#',
  13. '#Form.fk_addedBy#','#Form.date_added#'
  14. </cfquery>
  15.      </cfif>
  16.      </cfloop>
  17. </cfif>
  18.  
Thanks in advance,
Rach
Aug 11 '08 #1

✓ answered by acoder

Welcome to Bytes!

In the query, you're using #form.attachment1# and not using the counter to differentiate between uploads.

43 9825
acoder
16,027 Expert Mod 8TB
Welcome to Bytes!

In the query, you're using #form.attachment1# and not using the counter to differentiate between uploads.
Aug 12 '08 #2
bonneylake
769 512MB
Acoder,

That worked! can't believe it was so simple. Thank you. I was wondering if you wouldn't mind answering another question. I am wondering instead of it putting whats in my file into my database. i was wondering how would i put the name of the file in my database? because right now its putting whats in my document into the database instead of the name of the file. I came up with this, but i am not sure how i would combine #counter# and #upload_file# into the cfquery.

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="counter">
  5.       verify the form field exists 
  6.      <cfif structKeyExists(FORM, "attachment"& counter)>
  7.            try and upload it ...
  8.           <cffile action="upload" fileField="attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  9.           <CFSET UPLOAD_FILE=#FILE.SERVERFILE#>
  10.               <cfquery name="attachment" datasource="CustomerSupport">
  11.     exec usp_CS_Insertattachments
  12. '#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#UPLOAD_FILE#','#Form.fk_addedBy#','#Form.date_added#'
  13. </cfquery>
  14.      </cfif>
  15.      </cfloop>
  16. </cfif>
  17.  
Thanks in advance,
Rach
Aug 12 '08 #3
acoder
16,027 Expert Mod 8TB
cffile.serverfile should be enough. That will contain the unique file name saved on the server.
Aug 12 '08 #4
bonneylake
769 512MB
cffile.serverfile should be enough. That will contain the unique file name saved on the server.
Acoder,

that worked for uploading one file with its file name (the code i have above). But when i try to upload multiple files it will only upload 1 file with its file name.

If i have #counter# instead of #upload_file# in my cfquery it will upload 2 files but not with there file name. Any way i can get counter and upload_file in cfquery together?

heres the code i have again
Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="counter">
  5.       verify the form field exists 
  6.      <cfif structKeyExists(FORM, "attachment"& counter)>
  7.            try and upload it ...
  8.           <cffile action="upload" fileField="attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  9.           <CFSET UPLOAD_FILE=#file.serverfile#>
  10.               <cfquery name="attachment" datasource="CustomerSupport">
  11.     exec usp_CS_Insertattachments
  12. '#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#UPLOAD_FILE#',
  13. '#Form.fk_addedBy#','#Form.date_added#'
  14. </cfquery>
  15.      </cfif>
  16.      </cfloop>
  17. </cfif>
Thanks in advance,
Rach
Aug 12 '08 #5
acoder
16,027 Expert Mod 8TB
Replace UPLOAD_FILE with cffile.serverfile. Since you're in a loop, after each upload, cffile.serverfile will contain the name of the file uploaded to the server. Which version of Coldfusion are you using?
Aug 13 '08 #6
bonneylake
769 512MB
Acoder,

well i tried your idea an it puts the file name in there, but it wont let me upload multiple files. With cffile.serverfile in the cfquery it will only let me upload one file with its name. If i have #counter# in cfquery it will let me upload multiple files but wont let me put the name with it (which makes no sense to me). But as far as i know the version of coldfusion. The book i am using to help me out is 5.0, but i believe we have a newer version then that (but i got no clue what version that is).

but here is the updated code with cffile.serverfile in the cfquery
Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="counter">
  5.       verify the form field exists 
  6.      <cfif structKeyExists(FORM, "attachment"& counter)>
  7.            try and upload it ...
  8.           <cffile action="upload" fileField="attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  9.               <cfquery name="attachment" datasource="CustomerSupport">
  10.     exec usp_CS_Insertattachments
  11. '#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','
  12. #cffile.serverfile#','#Form.fk_addedBy#','#Form.date_added#'
  13. </cfquery>
  14.      </cfif>
  15.      </cfloop>
  16. </cfif>
i have also tried to take counter out of everything an when i did that it would let me upload 2 files.But for the first file uploaded it would give the correct file name, But then the 2nd file uploaded it renames the file completely (i am guessing trying to make it unique) although the 2nd file uploaded is a completely different name (the files i am using to test are named test1.txt and test2.txt).I think the code below would work if i could figure out what i am missing to it.Here is the code i tried without counter in it.

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="attachment">
  5.       verify the form field exists 
  6.      <cfif structKeyExists(FORM, "attachment")>
  7.            try and upload it ...
  8.           <cffile action="upload" fileField="attachment" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  9.               <cfquery name="attachment" datasource="CustomerSupport">
  10.     exec usp_CS_Insertattachments
  11. '#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#cffile.serverfile#',
  12. '#Form.fk_addedBy#','#Form.date_added#'
  13. </cfquery>
  14.      </cfif>
  15.      </cfloop>
  16. </cfif>
Thanks in advance,
Rach
Aug 13 '08 #7
acoder
16,027 Expert Mod 8TB
The cffile action="upload" tag is the one which uploads the file, not the cfquery tag.

The filefield attribute should have the name of the file, so use form.attachment#counter#.

To find out your Coldfusion version, check the Coldfusion Administrator, or, if you have debugging switched on, just check the debugging information at the bottom of each page.
Aug 13 '08 #8
bonneylake
769 512MB
Acoder,

Well i really don't know how to get a hold of the Coldfusion Administrator (boss in charge of that) and the only time i see the anything about coldfusion that comes up is when i make an error so unless i make an error i don't really know how else to get it. But i think i am between 5-7.

But you know how i said i changed the code by taking counter out? well i deleted all the files in my database an now when i add files it will add multiple files but it will instead of give it the name test1.txt it will rename it to like an example ACF39DD.TXT. I don't know if that tells you anything but i thought i would tell you that. But that is with the new code, i went back to the old code based on what you said about the counter. But here is what i changed with what you told me, but i think i am missing something because i still cant get it right.

Like right now it will upload one file with the file name. But it just won't upload multiple, an only reason it was doing it before was because #counter# was in the cfquery. I was thinking that maybe the counter is not working right because it seems like it follows through when i upload the first file but it doesn't want to loop through the code again to add a second file. Maybe need to change how the cfloop works? like maybe changing it.just an idea on the top of my head. But here is what the cfquery looks like right now

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="counter">
  5.       verify the form field exists 
  6.      <cfif structKeyExists(FORM, "attachment"& counter)>
  7.            try and upload it ...
  8.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  9.  <cfquery name="attachment" datasource="CustomerSupport">
  10.     exec usp_CS_Insertattachments
  11. '#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#cffile.serverfile#','#Form.fk_addedBy#','#Form.date_added#'
  12. </cfquery>
  13.      </cfif>
  14.      </cfloop>
  15. </cfif>
here is what the html looks like for it
Expand|Select|Wrap|Line Numbers
  1.  <input type="file" name="attachment" id="attachment" value="#attachment_ID_counter#" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
  2.           <div id="moreUploads"></div>
  3.           <div id="moreUploadsLink" style="display:none;">
  4.           <input type="button" value="Attach another file" 
  5.    onclick="javascript:addFileInput();" >
  6.           </div>
  7.           <input type="hidden" id="totalAttachments" name="totalAttachments" value="1">
but if you have any suggestions on where i could go from here i would really appreciate it because i am just lost. But thank you for all the help you have given me an if you got any suggestions let me know,

Thank you,
Rach
Aug 14 '08 #9
acoder
16,027 Expert Mod 8TB
Tell your boss to turn on debugging for you at least. That will contain a lot of useful information that will help you debug your application.

I've noticed that you've changed your HTML. It just has an input file element named "attachment", not "attachment1", "attachment2", etc. For the counter code to work, you will need the files to be named with 1, 2, 3, etc.
Aug 14 '08 #10
bonneylake
769 512MB
Acoder,

The attachment part was the problem! It totally fixed it, THANK YOU THANK YOU!!! i know i have asked you a lot of questions,which thank you for answering them all you have no idea how much you have helped me! But i was wondering if you wouldn't mind answering just one more.

I was wondering how would i rename the files after i upload them? an the name i wanted to give each file uploaded was like this attach_ID_count attach being the name of the file i am uploading, the id coming from the form.id in the cfquery, and count being the file being uploaded.

This is what i have come up with so far but wasent sure how to give it the right name an i was going to put this right under the upload part.

Expand|Select|Wrap|Line Numbers
  1. <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\">
but THANK YOU so much for all the help you have given me you truley have saved me!
Rach
Aug 14 '08 #11
acoder
16,027 Expert Mod 8TB
You're welcome :)

For the renaming, add it to the destination field. Create a variable with the new name and then use that, e.g. something like
Expand|Select|Wrap|Line Numbers
  1. <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  2. <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
Aug 14 '08 #12
bonneylake
769 512MB
Acoder,

All i can say is YOUR AWESOME! wow it works so beautiful i could cry. But THANK YOU so much for all the help :)

Rach

If anyone wants to see the finished action script code here it is.

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="counter">
  5.       verify the form field exists 
  6.      <cfif structKeyExists(FORM, "attachment"& counter)>
  7.            try and upload it ...
  8.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  9.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  10.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  11.               <cfquery name="attachment" datasource="CustomerSupport">
  12.     exec usp_CS_Insertattachments
  13. '#Form.ID#','#evaluate(serialnum)#','#description#','#filename#','#Form.fk_addedBy#','#Form.date_added#'
  14. </cfquery>
  15.      </cfif>
  16.      </cfloop>
  17. </cfif>
  18.  
Aug 14 '08 #13
acoder
16,027 Expert Mod 8TB
No problem, you're welcome (don't cry too much ;))

Just a note that you should probably add some error checking to be on the safe side.

Post again back to the forum should you have any more questions.
Aug 14 '08 #14
bonneylake
769 512MB
Hey Everyone,

Well didn't mean to come back to this question. But there is something else i would like to add to my upload (well actually realized i needed). Well i want to be able to remove a file that is uploaded. Like every time you upload a file a remove button appears on the side so that if the user decides they don't want to upload it they don't have to. I tried doing this by myself. But i am having problems with my coldfusion part. The problem i am having is with my description. Basically lets say i try to upload 3 files. I decide i don't need the second file so i click remove an then click upload. This is the error i get.

An error occurred while evaluating the expression:
currentDescription = form["description" & counter]
The member "DESCRIPTION2" in dimension 1 of object "form" cannot be found.

here is my code

javascript
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.   var upload_number = 2;
  3.      function addFileInput()
  4.      {
  5.      var d = document.createElement("div");
  6.      var l = document.createElement("a");
  7.      var file = document.createElement("input");
  8.      var text = document.createElement("input");
  9.      d.setAttribute("id", "f"+upload_number);
  10.      file.setAttribute("type", "file");
  11.      file.setAttribute("name", "attachment"+upload_number);
  12.      text.setAttribute("type", "text");
  13.      text.setAttribute("name", "description"+upload_number);
  14.      l.setAttribute("href", "javascript:removeFileInput('f"+upload_number+"');");
  15.      l.appendChild(document.createTextNode("Remove"));
  16.      d.setAttribute("id", "f"+upload_number);
  17.      d.appendChild(file);
  18.      d.appendChild(text);
  19.      d.appendChild(l);
  20.      document.getElementById("moreUploads").appendChild(d);
  21.      document.getElementById("totalAttachments").value = upload_number;
  22.      upload_number++;
  23.      }
  24.  
  25. function removeFileInput(i)
  26. {
  27.     var elm = document.getElementById(i);
  28.     document.getElementById("moreUploads").removeChild(elm);
  29.     upload_number = upload_number - 1;
  30. }
  31. </script>
form
Expand|Select|Wrap|Line Numbers
  1. <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
  2.  Description <input type="text" name="description1" id="description" value="" /> 
  3.           <div id="moreUploads"></div>
  4.           <div id="moreUploadsLink" style="display:none;">
  5.           <input type="button" value="Attach another file" 
  6.    onclick="javascript:addFileInput();" >
  7.           </div>
  8.           <input type="hidden" id="totalAttachments" name="totalAttachments" value="1">
  9.  
coldfusion
Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.totalAttachments" default="0">
  4.      <cfloop from="1" to="#form.totalAttachments#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6.       <!---verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.           <!--- try and upload it ...--->
  9.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  10.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  11.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  12.               <cfquery name="attachment" datasource="CustomerSupport">
  13.     exec usp_CS_Insertattachments
  14. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  15. </cfquery>
  16.      </cfif>
  17.      </cfloop>
  18. </cfif>
  19.  
Thanks in advance to anyone who can figure out my problem :)
Rach
Aug 18 '08 #15
acoder
16,027 Expert Mod 8TB
The problem is that when you remove the second one, you have a file input "f1" and file input "f3", so there's no f2 when you submit. One possible solution to this is to rename all lower inputs (3,4,5, etc.) with one less, so f3 becomes f2, f4 becomes f3, etc. and attachment3 becomes attachment2, description3 becomes description2, and so on.
Aug 19 '08 #16
bonneylake
769 512MB
Acoder,

I noticed that it was doing that yesterday when i was playing it doing f1,f2 and f3, an was thinking it had to do with the problem. i tried to take that part out of the whole thing but that didn't work to good. But how would i go about renaming it? i was looking at it yesterday an thinking it needed a count in there, but was not sure how to go about that in javascript.

Thank you again in advance,
Rach
Aug 19 '08 #17
acoder
16,027 Expert Mod 8TB
The basic idea is to use a loop which would loop from upload_Num_To_Remove+1 till total number of uploads. In our example of removing number 2 and having 3 file inputs, that would be only 3. In the loop, use setAttribute to change the name to one less, so 3 becomes 2.

This is now turning into a JavaScript question, so if you're still struggling with this, post a new thread in the JavaScript forum.
Aug 19 '08 #18
bonneylake
769 512MB
Hey Acoder,

yeah you are right this is more of a javascript problem then a coldfusion problem. I understand what your telling me about the loop, just having a hard time applying it. I posted my question over in the javascript forum an hope they can help me out.

But thank you for all your help acoder :),
Rach
Aug 19 '08 #19
acoder
16,027 Expert Mod 8TB
No problem. Good luck with your project!
Aug 20 '08 #20
bonneylake
769 512MB
Hey Acoder,

nope the thread is not over yet, which sorry for having so many threads. well i am still a bit lost on the server-side. i understand the changing the name from totalAttachments to uploads but the part about comma-delimited string has me thrown off. here is what i got

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "totalAttachments")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.uploads" default="0">
  4.      <cfloop from="1" to="#form.uploads#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6.       <!---verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.           <!--- try and upload it ...--->
  9.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  10.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  11.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  12.               <cfquery name="attachment" datasource="CustomerSupport">
  13.     exec usp_CS_Insertattachments
  14. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  15. </cfquery>
  16.      </cfif>
  17.      </cfloop>
  18. </cfif>
Thank you :),
Rach
Aug 27 '08 #21
acoder
16,027 Expert Mod 8TB
I've split your post from the other thread and merged with this one instead since it's rather more appropriate to this thread and unrelated to the other one.

You can use cfloop over a list, so you're looking for something like:
Expand|Select|Wrap|Line Numbers
  1. <cfloop list="#form.uploads#" index="counter">
Aug 27 '08 #22
bonneylake
769 512MB
Hey Acoder,

it worked! yay it works, it works!!! you have no idea how excited i am lol :). But THANK YOU SO MUCH FOR ALL THE HELP!!! an sorry if i was to much trouble. but THANK YOU, THANK YOU,

Rach


if anyone wants the results to the coldfusion here it is. if you want the javascript and html for this you can find it at this link http://bytes.com/forum/showthread.ph...99#post3330599

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "uploads")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.uploads" default="0">
  4.      <cfloop list="#form.uploads#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6.       <!---verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.           <!--- try and upload it ...--->
  9.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  10.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  11.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  12.               <cfquery name="attachment" datasource="CustomerSupport">
  13.     exec usp_CS_Insertattachments
  14. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  15. </cfquery>
  16.      </cfif>
  17.      </cfloop>
  18. </cfif>
  19.  
Aug 27 '08 #23
acoder
16,027 Expert Mod 8TB
LOL, yeah, it works.

Just one more thing that you should be aware of. You'll need to validate because you can never trust user input, so make sure the file has really been uploaded (and don't allow the user to upload just any file) before inserting info. into the database.
Aug 27 '08 #24
bonneylake
769 512MB
Hey Acoder,

Ran into one last problem (hope its the last problem). but when i tried earlier not to insert anything into the database i got this error


Expand|Select|Wrap|Line Numbers
  1.       Error processing CFFILE
  2.  
  3.       No data was received in the uploaded file '\' Saving empty (zero-length) files is prohibitted. Please make sure you specified the correct file.
heres the javascript
Expand|Select|Wrap|Line Numbers
  1.  var upload_number = 2;
  2.      function addFileInput()
  3.      {
  4.      var d = document.createElement("div");
  5.      var l = document.createElement("input");
  6.      var file = document.createElement("input");
  7.      var text = document.createElement("input");
  8.      var nbsp = document.createTextNode("\u00a0");
  9.      var space = document.createTextNode("\u00a0");
  10. <!---     var br = document.createElement("br");--->
  11.      var des = document.createTextNode("Description")
  12.      try {
  13.    file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
  14.    text = document.createElement("<input type='text' name='description"+upload_number+"'>");
  15.    l = document.createElement("<input type='button' onclick='javascript:removeFileInput("+upload_number+");'>");
  16. } catch (e) {
  17.   file = document.createElement("input");
  18.   text = document.createElement("input");
  19. }
  20.      d.setAttribute("id", "f"+upload_number);
  21.      file.setAttribute("type", "file");
  22.      file.setAttribute("name", "attachment"+upload_number);
  23.      text.setAttribute("type", "text");
  24.      text.setAttribute("name", "description"+upload_number);
  25.      l.setAttribute("id", "l"+upload_number);  
  26.      l.setAttribute("type", "button");
  27.      l.setAttribute("onclick", "javascript:removeFileInput("+upload_number+")");
  28.  
  29.      l.type="button";
  30.      l.value="Remove";
  31.      l.onclick="javascript:removeFileInput("+upload_number+")";
  32. <!---     l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");--->
  33. <!---     l.appendChild(document.createTextNode("Remove"));--->
  34.      d.setAttribute("id", "f"+upload_number);
  35.      d.appendChild(file);
  36.      d.appendChild(nbsp);
  37.      d.appendChild(des);
  38. <!---     d.appendChild(br);--->
  39.       d.appendChild(space);
  40.      d.appendChild(text);
  41.      d.appendChild(l);
  42.      document.getElementById("moreUploads").appendChild(d);
  43.      document.getElementById("uploads").value += "," + upload_number;
  44.      upload_number++;
  45.      }
  46.  
  47. function removeFileInput(i)
  48. {
  49.     var elm = document.getElementById("f"+i);
  50.     document.getElementById("moreUploads").removeChild(elm);
  51. document.getElementById("uploads").value = document.getElementById("uploads").value.replace(i,"");
  52.  
  53. }
html
Expand|Select|Wrap|Line Numbers
  1.  <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
  2.  Description <input type="text" name="description1" id="description" value="" /> 
  3.           <div id="moreUploads"></div>
  4.           <div id="moreUploadsLink" style="display:none;">
  5.           <input type="button" value="Attach another file" 
  6.    onclick="javascript:addFileInput();" >
  7.           </div>
  8.           <input type="hidden" name="uploads" id="uploads" value="1">
and coldfusion
Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "uploads")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.uploads" default="0">
  4.      <cfloop list="#form.uploads#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6.       <!---verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.           <!--- try and upload it ...--->
  9.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  10.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  11.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  12.               <cfquery name="attachment" datasource="CustomerSupport">
  13.     exec usp_CS_Insertattachments
  14. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  15. </cfquery>
  16.      </cfif>
  17.      </cfloop>
  18. </cfif>
Thank you again for all your help,
Rach
Aug 28 '08 #25
acoder
16,027 Expert Mod 8TB
Firstly, form.uploads should default to "" (the empty string).

Use a cftry/cfcatch around the cffile uploads to catch errors. You can get the error messages from the cffile variable.
Aug 28 '08 #26
bonneylake
769 512MB
Acoder,

Tried to do the cftry/cfcatch. but not really understanding. here is what i tried.

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "uploads")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.                <cftry>
  4.      <cfparam name="FORM.uploads" default="">
  5.      <cfloop list="#form.uploads#" index="counter">
  6.       <cfset currentDescription = form["description" & counter]>
  7.       <!---verify the form field exists --->
  8.      <cfif structKeyExists(FORM, "attachment"& counter)>
  9.           <!--- try and upload it ...--->
  10.           <cfcatch>
  11.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  12.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  13.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  14.               <cfquery name="attachment" datasource="CustomerSupport">
  15.     exec usp_CS_Insertattachments
  16. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  17. </cfquery>
  18.      </cfif>
  19.      </cfcatch>
  20.      </cfloop>
  21.           </cftry>
  22. </cfif>
Thank you,
Rach
Aug 28 '08 #27
acoder
16,027 Expert Mod 8TB
See how to use cftry (CF8).
Aug 28 '08 #28
bonneylake
769 512MB
Hey Acoder,

Hate to say it but i am still pretty lost. I am not sure what cftry needs to be wrapped around. An i am really not sure what the cfcatch is suppose to be.i know it needs to say something about cffile. But i don't know how to tell it that if there is no file being uploaded that it continues submitting the form. But here is what i tried.

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "uploads")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.uploads" default="">
  4.      <cfloop list="#form.uploads#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6.     <!---  verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.           <!--- try and upload it ...--->
  9.           <cftry>
  10.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  11.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  12.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  13.           <cfcatch type = "cffile">
  14.               <cfquery name="attachment" datasource="CustomerSupport">
  15.     exec usp_CS_Insertattachments
  16. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  17. </cfquery>
  18.      </cfif>
  19.      </cfcatch>
  20.      </cftry>
  21.      </cfloop>
  22. </cfif>
  23.  
Thank you again for the help,
Rach
Aug 29 '08 #29
acoder
16,027 Expert Mod 8TB
You may find this link useful.
Aug 29 '08 #30
bonneylake
769 512MB
Hey Acoder,

I have ran across that article before an had trouble following it. but i read his comment and by reading his comments it seems like cftry/cfcatch only lets you put your own error message? i am probably wrong but that is how i am taking it by reading it an that doesn't really solve the problem i am having. the thing with the upload is that probably half if not more of the time they will not upload a file an it really has to still submit if a file is there or not. It doesn't have to put an entry into the database just still when i click submit has to say file has been successfully uploaded.

but sorry i am not understanding this never deal with cftry or cfcatch before.

but thank you for your patience an helping me,

Rach
Aug 29 '08 #31
acoder
16,027 Expert Mod 8TB
Basically, a cftry/catch works like any other language. You put the code within the try section. If there's an error, you put the code that deals with the error (print out a message, ignore, etc.) in the cfcatch section. cfcatch.message will contain the error message.

You can use
Expand|Select|Wrap|Line Numbers
  1. <cfif Len(FORM["attacment#counter#"])>
to test if a file has zero length.

Make sure to match up the tags properly. In your last piece of code above, you have <cfcatch>/<cfif> improperly nested.
Aug 29 '08 #32
bonneylake
769 512MB
Hey Acoder,

well i am still doing something wrong just not sure what. i bolded what i have added.

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "uploads")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.uploads" default="">
  4.      <cfloop list="#form.uploads#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6. <!---      verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.      <!---      try and upload it ...--->
  9.           <cftry>
  10.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  11.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  12.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  13.           <cfcatch type = "cffile">
  14.      <cfif Len(FORM["attacment#counter#"])>
  15.               <cfquery name="attachment" datasource="CustomerSupport">
  16.     exec usp_CS_Insertattachments
  17. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  18. </cfquery>
  19. </cfif>
  20.      </cfcatch>
  21.      </cftry>
  22.      </cfif>
  23.      </cfloop>
  24. </cfif>
  25.  
  26.  
Thank you for the help an sorry i seem to be making this difficult,

Rach
Aug 29 '08 #33
acoder
16,027 Expert Mod 8TB
I've not tested this, but try something like:
Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "uploads")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.uploads" default="">
  4.      <cfloop list="#form.uploads#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6. <!---      verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.      <!---      try and upload it ...--->
  9.           <cftry>
  10.      <cfif Len(FORM["attachment#counter#"])>
  11.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  12.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  13.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  14.               <cfquery name="attachment" datasource="CustomerSupport">
  15.     exec usp_CS_Insertattachments
  16. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  17. </cfquery>
  18.         </cfif>
  19.           <cfcatch><!--- do something here, e.g. display error message.. --->
  20.      </cfcatch>
  21.      </cftry>
  22.      </cfloop>
  23. </cfif>
Aug 29 '08 #34
bonneylake
769 512MB
Hey Acoder,

When i tried that i got the error of

Context validation error in tag CFIF

The tag is not correctly positioned relative to other tags in the template: tag CFIF must have some content. This means that there must be at least one tag, some text, or even just whitespace characters between the <CFIF> and </CFIF> markers.

This problem may be due to a CFML comment that has no end comment mark.


Any suggestions?

Thank you,
Rach
Aug 29 '08 #35
acoder
16,027 Expert Mod 8TB
I accidentally deleted the closing <cfif> tag after cftry (compare it to what you had earlier). I did say I hadn't tested it ;)
Aug 29 '08 #36
bonneylake
769 512MB
Hey Acoder,

I know you had not tested it, just saying i had gotten an error :), an i was just looking at the cfif to before i read your reply lol. But it worked, YAY ,IT WORKED!!! i can't believe its working!!! Thank you so much for all the help you have no idea how much it means to me!!!

Thank you, THANK YOU!!!! :) :) :),
Rach

if anyone wants the results here is the results
Expand|Select|Wrap|Line Numbers
  1.  <cfif structKeyExists(FORM, "uploads")>
  2.            <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.            <cfparam name="FORM.uploads" default="">
  4.            <cfloop list="#form.uploads#" index="counter">
  5.             <cfset currentDescription = form["description" & counter]>
  6.       <!---      verify the form field exists --->
  7.            <cfif structKeyExists(FORM, "attachment"& counter)>
  8.            <!---      try and upload it ...--->
  9.                 <cftry>
  10.            <cfif Len(FORM["attachment#counter#"])>
  11.                 <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  12.                 <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  13.                 <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\  form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\  form\attachments\#filename#">
  14.                     <cfquery name="attachment" datasource="CustomerSupport">
  15.           exec usp_CS_Insertattachments
  16.       '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  17.       </cfquery>
  18.               </cfif>
  19.                 <cfcatch><!--- do something here, e.g. display error message.. --->
  20.            </cfcatch>
  21.            </cftry>
  22.            </cfif>
  23.            </cfloop>
  24.       </cfif>
  25.  
Aug 29 '08 #37
acoder
16,027 Expert Mod 8TB
Hey, glad to see that it worked :)

Just a couple of points: if an error occurs in the uploading, you may want to delete already uploaded files and you may not want to add records to the database (see the earlier link for an example of what I mean - he uses an array to keep track of the uploaded files). If you're using a stored procedure, it may be better to use cfstoredproc instead of cfquery.
Aug 29 '08 #38
bonneylake
769 512MB
Hey Acoder,

yeah you are right about the deleting the files being upload. but thing about the upload is i really have a hard time seeing the upload fail because it runs off of a server an doesn't actually use the internet. if internet dies it don't affect the form . also i been doing lots of uploading with heavy files an haven't run into any trouble. but of course i know it don't mean i wont run into trouble. But i don't even know where i would begin adding the part about deleting the file because there is so much to it already an i am terrified i will screw it up if i try lol.But also because, if you have heard about hurricane gustav, i am right in the path of it an i don't know when all be able to try to test it again till i am at work because everything i need is at work aand with this storm coming in i got no clue whats going to happen. An the reason i have not used cfstoredproc (your not the first to tell me) is simply because this is how my work does it an they haven't run into any trouble with it yet. if it was my choice i would of already changed it to cfstoredproc based on what you an everyone else has said. but because of how my worked showed me how to do it i don't feel i have the right to argue with how they did it also because i only know so much about coldfusion an don't feel i know enough to argue. But Thank you so much acoder, you have no clue how much this means to me, but also i have learned so much more about coldfusion and javascript thanks to you :). so thank you for having patience with me an also for helping me i really do appreciate it all.

Thank you again, you are awesome :)!!!
Rach
Aug 31 '08 #39
acoder
16,027 Expert Mod 8TB
You're welcome, of course :)

You could probably add these things to a list of things to do as you become more proficient in Coldfusion. Other things would be validation, cfqueryparam for any user input to help prevent SQL injection, error handling to display proper error pages when users encounter errors, etc. - basically all down the security line. Am I right in thinking this is for an intranet? Even if it is, you should be wary in being lax on security. The basic mantra is "never trust user input".

Anyway, it's working on a basic level. Good luck on the rest of your project.

PS. hadn't heard about the hurricane. Hope all goes well.
Aug 31 '08 #40
bonneylake
769 512MB
You're welcome, of course :)

You could probably add these things to a list of things to do as you become more proficient in Coldfusion. Other things would be validation, cfqueryparam for any user input to help prevent SQL injection, error handling to display proper error pages when users encounter errors, etc. - basically all down the security line. Am I right in thinking this is for an intranet? Even if it is, you should be wary in being lax on security. The basic mantra is "never trust user input".

Anyway, it's working on a basic level. Good luck on the rest of your project.

PS. hadn't heard about the hurricane. Hope all goes well.
Hey Acoder,

yep you are right it is for an intranet. An yes i know there will come more things that will be needed to be add to this when the time comes. For now just trying to come up with the basics an when i run into those problems like you have said then i will fix them. i know my entire form will have to have adjustments based on the users. but for now just having the basics an plan on tweaking it when we start hearing the complaints lol. But still thank you for your help :). an yeah i hope the hurricane goes well to, i know i am worried lol

Thank you again :),
Rach
Aug 31 '08 #41
bonneylake
769 512MB
Hey Everyone,

Well i hate to come back to a question i had solved, but i do have another problem.i am not sure if this needs to be here or in javascript one i started which here is the link to the javascript part of this question.

http://bytes.com/forum/showthread.ph...01#post3321901

Anyway, I am wondering, how would i add an alert to this to make it so that a user can not submit the form till any and all files the user wants to attach has a description?

here is what i have on the form part of it
Expand|Select|Wrap|Line Numbers
  1.  <input type="file" name="attachment1" id="attachments" value="1" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
  2.  Description <input type="text" name="description1" id="description" value="" /> 
  3.           <div id="moreUploads"></div>
  4.           <div id="moreUploadsLink" style="display:none;">
  5.           <input type="button" value="Attach another file" 
  6.    onclick="javascript:addFileInput();" >
  7.           </div>
  8.           <input type="hidden" name="uploads" id="uploads" value="1">
an here is what i have once i submit the attachment
Expand|Select|Wrap|Line Numbers
  1. <!---Inserts attachments into attachments table--->
  2.       <cfif structKeyExists(FORM, "uploads")>
  3.            <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  4.            <cfparam name="FORM.uploads" default="">
  5.            <cfloop list="#form.uploads#" index="counter">
  6.             <cfset currentDescription = form["description" & counter]>
  7.       <!---      verify the form field exists --->
  8.            <cfif structKeyExists(FORM, "attachment"& counter)>
  9.            <!---      try and upload it ...--->
  10.                 <cftry>
  11.            <cfif Len(FORM["attachment#counter#"])>
  12.                 <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  13.                 <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  14.                   <!---           IF RUN INTO PROBLEMS WITH FILES NOT GOING INTO TABLE MAKE SURE EVERYTHING BETWEEN SOURCE="" IS ALL ON ONE LINE--->
  15.      <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" 
  16.                 destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  17.                     <cfquery name="attachment" datasource="CustomerSupport">
  18.           exec usp_CS_Insertattachments
  19.       '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  20.       </cfquery>
  21.               </cfif>
  22.                 <cfcatch><!--- do something here, e.g. display error message.. --->
  23.            </cfcatch>
  24.            </cftry>
  25.            </cfif>
  26.            </cfloop>
  27.       </cfif>
Thank you in advance,
Rach
Sep 29 '08 #42
acoder
16,027 Expert Mod 8TB
This would be a JavaScript question, but it should probably have its own thread because it's significantly different from the original problem.

Note that you should have this check in your Coldfusion code too.
Sep 29 '08 #43
bonneylake
769 512MB
This would be a JavaScript question, but it should probably have its own thread because it's significantly different from the original problem.

Note that you should have this check in your Coldfusion code too.
Hey Acoder,

yeah i figured it needed to be in another, but thought i would ask anyway :). But i started a new thread http://bytes.com/forum/showthread.ph...77#post3369877
Thank you,
Rach
Sep 29 '08 #44

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris Mosser | last post by:
I'm looking for an applet that allows for multiple file uploads. I found jupload and am considering using that, but I might have a couple issues. I need to build a web app for a print shop, that...
6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
2
by: G | last post by:
Hello Friend, I am handling a module using ASP3.0 which has to upload an movie clipsof size 1 mb or 2 mb. i have a code which upload only files or images. So I need your help for this. If you...
3
by: dreamznatcher | last post by:
Hello, I found a script here: http://www.webtoolkit.info/ajax-file-upload.html which supposedly allows you to upload files using AJAX (I'm not an expert). The site claims it's the best way to...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
9
by: torso | last post by:
Hi Does someone know a good tutorial for multiple file upload with xmlHttpRequest. I am trying to do directory upload. So I could choose directorys and upload those to the server. Another...
4
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.