 | 
August 11th, 2008, 04:44 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| | upload multiple files like gmail problem.
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). - <cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#Form.serialnum#','#Form.attachdescrip#','#Form.attachment1#',
-
'#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
But here is the full code
javascript that lets you upload multiple files - <script type="text/javascript">
-
var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var file = document.createElement("input");
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
d.appendChild(file);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("totalAttachments").value = upload_number;
-
upload_number++;
-
}
-
</script>
-
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 - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
verify the form field exists
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
try and upload it ...
-
<cffile action="upload" fileField="attachment#counter#" destination=
-
"C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#Form.serialnum#','#Form.attachdescrip#','#Form.attachment1#',
-
'#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
-
Thanks in advance,
Rach
Last edited by acoder; August 12th, 2008 at 10:44 AM.
Reason: Added [code] tags
| 
August 12th, 2008, 10:43 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
Welcome to Bytes!
In the query, you're using #form.attachment1# and not using the counter to differentiate between uploads.
| 
August 12th, 2008, 03:34 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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. -
<cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
verify the form field exists
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
try and upload it ...
-
<cffile action="upload" fileField="attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<CFSET UPLOAD_FILE=#FILE.SERVERFILE#>
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#UPLOAD_FILE#','#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
-
Thanks in advance,
Rach
| 
August 12th, 2008, 04:43 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
cffile.serverfile should be enough. That will contain the unique file name saved on the server.
| 
August 12th, 2008, 06:57 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| | Quote: |
Originally Posted by acoder 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 - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
verify the form field exists
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
try and upload it ...
-
<cffile action="upload" fileField="attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<CFSET UPLOAD_FILE=#file.serverfile#>
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#UPLOAD_FILE#',
-
'#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
Thanks in advance,
Rach
| 
August 13th, 2008, 10:21 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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?
| 
August 13th, 2008, 02:48 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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 -
<cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
verify the form field exists
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
try and upload it ...
-
<cffile action="upload" fileField="attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','
-
#cffile.serverfile#','#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</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. - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="attachment">
-
verify the form field exists
-
<cfif structKeyExists(FORM, "attachment")>
-
try and upload it ...
-
<cffile action="upload" fileField="attachment" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#cffile.serverfile#',
-
'#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
Thanks in advance,
Rach
| 
August 13th, 2008, 08:32 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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.
| 
August 14th, 2008, 04:02 AM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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 - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
verify the form field exists
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
try and upload it ...
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#Form.attachdescrip#','#cffile.serverfile#','#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
here is what the html looks like for it - <input type="file" name="attachment" 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">
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
| 
August 14th, 2008, 09:06 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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.
| 
August 14th, 2008, 02:32 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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. - <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
| 
August 14th, 2008, 04:56 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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 - <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
| 
August 14th, 2008, 07:19 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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. - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
verify the form field exists
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
try and upload it ...
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#description#','#filename#','#Form.fk_addedBy#','#Form.date_added#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
-
| 
August 14th, 2008, 08:15 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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.
| 
August 18th, 2008, 09:38 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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 - <script type="text/javascript">
-
var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("a");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("href", "javascript:removeFileInput('f"+upload_number+"');");
-
l.appendChild(document.createTextNode("Remove"));
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("totalAttachments").value = upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById(i);
-
document.getElementById("moreUploads").removeChild(elm);
-
upload_number = upload_number - 1;
-
}
-
</script>
form - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<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">
-
coldfusion - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
<cfset currentDescription = form["description" & counter]>
-
<!---verify the form field exists --->
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
<!--- try and upload it ...--->
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
-
Thanks in advance to anyone who can figure out my problem :)
Rach
| 
August 19th, 2008, 11:48 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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.
| 
August 19th, 2008, 06:47 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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
| 
August 19th, 2008, 10:31 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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.
| 
August 19th, 2008, 10:56 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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
| 
August 20th, 2008, 09:58 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
No problem. Good luck with your project!
| 
August 27th, 2008, 03:46 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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 - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.uploads" default="0">
-
<cfloop from="1" to="#form.uploads#" index="counter">
-
<cfset currentDescription = form["description" & counter]>
-
<!---verify the form field exists --->
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
<!--- try and upload it ...--->
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
Thank you :),
Rach
| 
August 27th, 2008, 04:41 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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: - <cfloop list="#form.uploads#" index="counter">
| 
August 27th, 2008, 06:56 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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 - <cfif structKeyExists(FORM, "uploads")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.uploads" default="0">
-
<cfloop list="#form.uploads#" index="counter">
-
<cfset currentDescription = form["description" & counter]>
-
<!---verify the form field exists --->
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
<!--- try and upload it ...--->
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
-
| 
August 27th, 2008, 07:18 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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.
| 
August 28th, 2008, 05:27 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 695
| |
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 - Error processing CFFILE
-
-
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 - var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("input");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
var nbsp = document.createTextNode("\u00a0");
-
var space = document.createTextNode("\u00a0");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
l = document.createElement("<input type='button' onclick='javascript:removeFileInput("+upload_number+");'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("type", "button");
-
l.setAttribute("onclick", "javascript:removeFileInput("+upload_number+")");
-
-
l.type="button";
-
l.value="Remove";
-
l.onclick="javascript:removeFileInput("+upload_number+")";
-
<!--- l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");--->
-
<!--- l.appendChild(document.createTextNode("Remove"));--->
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
d.appendChild(nbsp);
-
d.appendChild(des);
-
<!--- d.appendChild(br);--->
-
d.appendChild(space);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," + upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
document.getElementById("uploads").value = document.getElementById("uploads").value.replace(i,"");
-
-
}
html - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" name="uploads" id="uploads" value="1">
and coldfusion - <cfif structKeyExists(FORM, "uploads")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.uploads" default="0">
-
<cfloop list="#form.uploads#" index="counter">
-
<cfset currentDescription = form["description" & counter]>
-
<!---verify the form field exists --->
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
<!--- try and upload it ...--->
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
Thank you again for all your help,
Rach
| 
August 28th, 2008, 05:49 PM
| | | | |