3 Replies - 5191 Views - Last Post: 25 June 2012 - 06:51 PM Rate Topic: -----

#1 xiow niow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-June 12

multiple selected file into one form upload in coldfusion

Posted 22 June 2012 - 09:05 PM

Hi there, here need to ask about any function available in cold fusion that able to do
an upload function like "GMail" does, which is can select multiple file in one time and direct upload
the file. Just hold the "Ctrl" key and click the needed file for upload.

here I did an upload function, but it based on various reference @ internet.

<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>
<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:\ColdFusion9\wwwroot\RegStudent\download\"
                        nameconflict="MAKEUNIQUE">
         	</cfif>
         </cfloop>
</cfif>
    
<cfinclude template="header.cfm">

<cfif not isDefined ("form.submit_upload")>
            <table align="center">
                <tr>
                    <td>
                    <br>
                        <form action='./create.cfm?type=create' method="POST" name="frmupload" enctype="multipart/form-data">
                            <input type="file" name="attachment1" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display = 'block';">
                            <div id="moreUploads"></div>
                            <div id="moreUploadsLink" style="display:none;"><a href="javascript:addFileInput();" style="color:#0000ad;">Attach another File</a></div>
                            <input type="hidden" name="totalAttachments" value="1">
                            <br><br>
                            <input type="submit" value="UPLOAD">
                        </form>
                    </td>
                </tr>
                
            </table>
            <p>&nbsp; </p>
            <div align="center">
            <cfoutput><h5><font color="##FF00FF"> <a href="index.cfm">HOME </a></font></h5></cfoutput>
            </div>
            
</cfif>
<br><br>

<cfinclude template="footer.cfm">
	



Any idea if I can edit my code into the one like "Gmail" does, which is just browse the file upload, use "Ctrl" key then select any file (more than one), and then upload all the selected file.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: multiple selected file into one form upload in coldfusion

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 856
  • View blog
  • Posts: 2,246
  • Joined: 28-March 11

Re: multiple selected file into one form upload in coldfusion

Posted 22 June 2012 - 09:09 PM

I moved from the Tutorial section. Please don't post questions in the tutorial section.
Was This Post Helpful? 0
  • +
  • -

#3 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1866
  • View blog
  • Posts: 3,389
  • Joined: 13-January 08

Re: multiple selected file into one form upload in coldfusion

Posted 25 June 2012 - 04:29 AM

Hi xiao noiw and welcome to DIC!

A multiple file upload function is something that most web dev languages have to roll on their own. The reason is that the HTML form tag doesn't support a single "file" button that allows you to specify multiple files to upload. So, you'd need to build some type of dynamic file script that, for instance, gives the user an "add file for upload" button and clicking that button creates a new form element of type "file". CF doesn't get involved in something like that.

That's if you want retain an HTML interface. Now, if you want to use some of the Flash connectivity that CF offers, there are solutions on the web for that but, instead of a Javascript function you'd be using a Flash solution. In either case, it's not a strictly CF issue.

For various example for how folks have tackled this issue (GMail went the Javascript route with a nifty Ajax function thrown in for good measure) you can check this Googled search and see what works for you.

Good luck!
Was This Post Helpful? 1
  • +
  • -

#4 xiow niow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-June 12

Re: multiple selected file into one form upload in coldfusion

Posted 25 June 2012 - 06:51 PM

Thanks Craig328, for the information.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1