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,wh en 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).
[CODE=cfm] <cfquery name="attachmen t" datasource="Cus tomerSupport">
exec usp_CS_Insertat tachments
'#Form.ID#','#F orm.serialnum#' ,'#Form.attachd escrip#','#Form .attachment1#',
'#Form.fk_added By#','#Form.dat e_added#'
</cfquery>
[/CODE]
But here is the full code
javascript that lets you upload multiple files
here is the upload page
[HTML]<form action="userfor m.cfm" id="userForm" name="userForm" method="POST"
enctype="multip art/form-data">
<input type="file" name="attachmen t1" id="attachment " value="#attachm ent_ID_counter# "
onchange="docum ent.getElementB yId('moreUpload sLink').style.d isplay = 'block';" />
<div id="moreUploads "></div>
<div id="moreUploads Link" style="display: none;">
<input type="button" value="Attach another file"
onclick="javasc ript:addFileInp ut();" >
</div>
<input type="hidden" id="totalAttach ments" name="totalAtta chments" value="1">
<input type="submit" class="officals ubmit" value="submit" name="submit"
onClick="return validate_form() ;">
</form>
[/HTML]
here is my action page
Thanks in advance,
Rach
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,wh en 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).
[CODE=cfm] <cfquery name="attachmen t" datasource="Cus tomerSupport">
exec usp_CS_Insertat tachments
'#Form.ID#','#F orm.serialnum#' ,'#Form.attachd escrip#','#Form .attachment1#',
'#Form.fk_added By#','#Form.dat e_added#'
</cfquery>
[/CODE]
But here is the full code
javascript that lets you upload multiple files
Code:
<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>
[HTML]<form action="userfor m.cfm" id="userForm" name="userForm" method="POST"
enctype="multip art/form-data">
<input type="file" name="attachmen t1" id="attachment " value="#attachm ent_ID_counter# "
onchange="docum ent.getElementB yId('moreUpload sLink').style.d isplay = 'block';" />
<div id="moreUploads "></div>
<div id="moreUploads Link" style="display: none;">
<input type="button" value="Attach another file"
onclick="javasc ript:addFileInp ut();" >
</div>
<input type="hidden" id="totalAttach ments" name="totalAtta chments" value="1">
<input type="submit" class="officals ubmit" value="submit" name="submit"
onClick="return validate_form() ;">
</form>
[/HTML]
here is my action page
Code:
<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>
Rach
Comment