Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cffile upload, are multiple uploads possible

Status
Not open for further replies.

cwt1971

Programmer
Joined
Jan 28, 2004
Messages
3
Location
US
Hello out there, how's it going?

Anyway, need to know if there is a way to <cffile action = &quot;upload&quot;> other than using an <input type=&quot;file&quot;>. Currently, I have the following:
*****************************************************

<body>
<form name=&quot;formUpload&quot; id=&quot;formUpload&quot; action=&quot;form_upld.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>
<input type=&quot;file&quot; name=&quot;ul_path&quot; id=&quot;ul_path&quot; width=&quot;300&quot;>
<input type=&quot;submit&quot; name=&quot;upload_now&quot; id=&quot;upload_now&quot; value=&quot;Submit File&quot;>
</form>
<cfset theDirReal = &quot;C:\Inetpub\<cfset theDirWeb = &quot;<cfif isdefined(&quot;FORM.upload_now&quot;)>
<!--- --->
<cffile action=&quot;upload&quot; filefield=&quot;ul_path&quot; nameconflict=&quot;makeunique&quot;
destination=&quot;#theDirReal#&quot;>

<!--- <cffile action=&quot;copy&quot;> --->
File Uploaded Successfully...
</cfif>
</body>

*****************************************************
can you use a cf variable in the filefield att. instead of the <input type=&quot;file&quot;>? I tried and my error involves the destination att., with a NULL value.

Also, does anyone know of any means to upload multiple files from a source? I tried this as well, by the same process with the var, and ripping the cffile thru a cfloop using an array, but nothing good happens. Any help or suggestions would be cool, even if you flat out tell me &quot;NO, that can't be done...&quot;

Regards,
Chris
 
Here's a pretty cool Java applet called AppletFile built specifically for uploading multiple files at once.


It's been a couple of years since I used it, so it may have changed some. When I downloaded the trial, it had several working examples of how to use it with CF (and ASP). The examples were not encrypted so it was pretty easy to see the code I needed to figure out how to use it in my CF pages.

Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
I wrote a little custom tag to do this.
I saved this code as wg_MultiFileUpload.cfm.....
<!--- **********************************************************************************
*
* Developer: Wayne Gipson
* Date: December 1 2003
* Project: Multiple File Upload Custom Tag
* Purpose: Allow the user to upload multiple files with only 1 browse box.
*
* The following parameters are optional:
* tableStyle: this is the class field for the table holding the checkbox and file name
* tdStyle: the table field holding the file name and check box
* tsStyleOff: the off color row. This is so the file table has different colored rows.
* trStyle: the row holding the td holding the checkbox and file name
* thStyle: the table header that says Upload Queue style.
* inputStyle: this is the class of the browse button
* checkBoxStyle: this is the class of the check box
* addButtonStyle: this is the style of the add button
* removeButtonStyle: this is the class of the remove button
*
* How To Use:
* For this function to work the programmer will need to have a form field on their
* page. place a reference to this code in between the form tags. The only thing the
* programmer will need to do is add an action page looping for file__ to get the
* fields.
**************************************************************************************** --->
<cfparam name=&quot;attributes.tableStyle&quot; default=&quot;&quot;>
<cfparam name=&quot;attributes.tdStyle&quot; default=&quot;&quot;>
<cfparam name=&quot;attributes.tdStyleOff&quot; default=&quot;#attributes.tdStyle#&quot;>
<cfparam name=&quot;attributes.trStyle&quot; default=&quot;&quot;>
<cfparam name=&quot;attributes.thStyle&quot; default=&quot;&quot;>
<cfparam name=&quot;attributes.inputStyle&quot; default=&quot;&quot;>
<cfparam name=&quot;attributes.checkBoxStyle&quot; default=&quot;&quot;>
<cfparam name=&quot;attributes.addButtonStyle&quot; default=&quot;&quot;>
<cfparam name=&quot;attributes.removeButtonStyle&quot; default=&quot;&quot;>
<cfoutput>
<script type=&quot;text/javascript&quot;>
var fileNumber=0;
var rowNumber=1;
function moveValue()
{
//check to see if there is a value in the file field
if(document.getElementById(&quot;file__&quot;+fileNumber).value)
{
deleteStyle=&quot;#attributes.removeButtonStyle#&quot;;
browseStyle=&quot;#attributes.checkBoxStyle#&quot;;
tableStyle=&quot;#attributes.tableStyle#&quot;;
trStyle=&quot;#attributes.trStyle#&quot;;
tdStyle=&quot;#attributes.tdStyle#&quot;;
//tdStyleOff=&quot;#attributes.tdStyleOff#&quot;;

if(rowNumber%2==0)
tdStyle=&quot;#attributes.tdStyle#&quot;;
else
tdStyle=&quot;#attributes.tdStyleOff#&quot;;
//place a holding div next to a div already in the form
//place a holding div next to a div already in the form
document.getElementById(&quot;fileDiv&quot;).insertAdjacentHTML(&quot;AfterEnd&quot;,&quot;<div id='div&quot;+fileNumber+&quot;'>&quot;);

document.getElementById(&quot;div&quot;+fileNumber).innerHTML=&quot;<table id='table&quot;+fileNumber+&quot;' width='100%'>&quot;+
&quot;<tr id='tr&quot;+fileNumber+&quot;' class='&quot;+trStyle+&quot;'>&quot;+
&quot;<td id='col_one_&quot;+fileNumber+&quot;' class='&quot;+tdStyle+&quot;' align='left'>&quot;+
document.getElementById(&quot;file__&quot;+fileNumber).value+
&quot;</td>&quot;+
&quot;<td id='col_two_&quot;+fileNumber+&quot;' class='&quot;+tdStyle+&quot;' align='right'>&quot;+
&quot;<input type='button' onClick='removeDiv(this);' id='&quot;+fileNumber+&quot;' value='Remove' class='&quot;+deleteStyle+&quot;'>&quot;+
&quot;</td>&quot;+
&quot;</tr>&quot;+
&quot;</table>&quot;;

//make the old file input disapear
document.getElementById(&quot;file__&quot;+fileNumber).style.display=&quot;none&quot;;
//increment the file number so we can create the next one
fileNumber++;
rowNumber++;
//put a value in the numFiles so we know how many files we need to loop through on server side
document.getElementById(&quot;numFiles&quot;).value=fileNumber;
//call the function to make the make the new file input field
makeNewInput();
}
else
alert(&quot;Please click browse and select a value&quot;);
}
function makeNewInput()
{
//create a new element of type input
var inputElem = document.createElement(&quot;input&quot;);
//set the type attribute to file
inputElem.setAttribute(&quot;type&quot;,&quot;file&quot;);
//set the name attribute to file0 or file1 and so on
inputElem.setAttribute(&quot;name&quot;,&quot;file__&quot;+fileNumber);
//set the id attribute to file0 or file1 and so on
inputElem.setAttribute(&quot;id&quot;,&quot;file__&quot;+fileNumber);
//inputElem.setAttribute(&quot;onkeydown&quot;,&quot;return false;&quot;);
//set the class or style
inputElem.setAttribute(&quot;class&quot;,&quot;#attributes.inputStyle#&quot;);
//insert the new file input field in the div
document.getElementById(&quot;fileDivs&quot;).appendChild(inputElem);
document.getElementById(&quot;file__&quot;+fileNumber).attachEvent(&quot;onkeydown&quot;,noKeys);
}
function removeDiv(toRemove)
{
if(document.getElementById(&quot;div&quot;+toRemove.id))
{
document.getElementById(&quot;div&quot;+toRemove.id).removeNode(true);
}
if(document.getElementById(&quot;file__&quot;+toRemove.id))
{
document.getElementById(&quot;file__&quot;+toRemove.id).removeNode(true);
}

}
function noKeys()
{
return false;
}
</script>
<input type=&quot;hidden&quot; name=&quot;numFiles&quot; id=&quot;numFiles&quot; value=&quot;0&quot;>
<input type=&quot;hidden&quot; name=&quot;activeFiles&quot; id=&quot;activeFiles&quot;>
<div name=&quot;fileDivs&quot; id=&quot;fileDivs&quot;>
<input type=&quot;file&quot; name=&quot;file__0&quot; id=&quot;file__0&quot; class=&quot;#attributes.inputStyle#&quot; onKeyDown=&quot;return false;&quot;>
</div>

<input type=&quot;button&quot; onClick=&quot;moveValue();&quot; value=&quot;Add File&quot; class=&quot;#attributes.addButtonStyle#&quot;>
<!---
<input type=&quot;button&quot; onClick=&quot;removeDiv();&quot; value=&quot;Delete File&quot; class=&quot;#attributes.removeButtonStyle#&quot;>
--->
<table border=&quot;1&quot; id=&quot;testTable&quot; class=&quot;#attributes.tableStyle#&quot;>
<tr class=&quot;#attributes.trStyle#&quot;>
<th colspan=&quot;2&quot; class=&quot;#attributes.thStyle#&quot;>
Upload Queue
</th>
</tr>
<tr class=&quot;#attributes.trStyle#&quot;>
<td class=&quot;#attributes.tdStyle#&quot;>
<div id=&quot;fileDiv&quot;>
</div>
</td>
</tr>
<tr id=&quot;bottomRow&quot; name=&quot;bottomRow&quot;>
<td id=&quot;insideTD&quot; name=&quot;insideTD&quot;>
</td>
</tr>
</table>
</cfoutput>


<!--- this is the end of the custom tag --->

Then in my first page i referenced the file like this:

<body>
This is a test page
<FORM name=&quot;form1&quot; id=&quot;form1&quot; action=&quot;uploadAction.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>

<cf_wg_MultiFileUpload tdStyle=&quot;Chart&quot; tableStyle=&quot;newClass&quot; thStyle=&quot;ChartHEADING&quot;>
<!---
<cf_wg_CheckMultiUpload>
--->
<input type=&quot;submit&quot; value=&quot;Submit Form&quot;>
</FORM>
<BR>
</body>



then, in my action page i did this:

<cfif form.numFiles GT 0>
<cfloop list=&quot;#form.fieldnames#&quot; index=&quot;i&quot;>
<cfif i contains &quot;file__&quot;>
<cfif len(evaluate(&quot;form.&quot;&i))>
<CFSET sPath = listdeleteat(GetCurrentTemplatePath(),listlen(GetCurrentTemplatePath(),&quot;\&quot;),&quot;\&quot;)>
<cfset filePath = sPath&&quot;\uploadedDocs\&quot;>
<cffile action=&quot;upload&quot;
filefield=&quot;#i#&quot;
destination=&quot;#filePath#&quot;
nameconflict=&quot;OVERWRITE&quot;>
</cfif>
</cfif>
</cfloop>
</cfif>


I hope this helps. Let me know if you need this further explained, or have suggestions to make it better. Im always willing to change things to make them better.

RackboyUT
 
RackboyUT or whoever sees this,

The code that you have looks pretty long, although so is mine. Here's the code for the page I'm working on. This page displays 2 <cfdirectory>'s (from cf vars: theDirLocal and theDirRemote) within tables. On the left dir, under column File Name 2, each name is link to the JavaScript:AddToList(theName). All what the JS function does is sets 2 Form var and submits. Then the code in blue is excuted. With the <cffile> commented out, it displays the file name to transfer on the top of the table. The problem is the <cffile> tag isn't working and I'm getting frightened and confused. ;-) It's not working with my form and I'm running out of ideas on how to get this to work, if it's possible. I'm a newbie at this <cffile> and thought someone out there may have an ideas. Thank you in advance..

;-)
Chris
******************************************************

<html>
<head>
<title>Download Form...(form_dnld.cfm) </title>
<link rel=&quot;stylesheet&quot; href=&quot;tirstyle1.css&quot; type=&quot;text/css&quot;>
<script language=&quot;JavaScript&quot;>
function AddToList(theFile){
document.forms.Form1.doTransfer.value = 1
document.forms.Form1.fileName.value = theFile
document.forms.Form1.method = &quot;post&quot;;
document.forms.Form1.submit();
}
</script>
</head>

<body>
<form name=&quot;Form1&quot; enctype=&quot;multipart/form-data&quot;>
<input type=&quot;hidden&quot; name=&quot;doTransfer&quot; value=&quot;0&quot;>
<input type=&quot;hidden&quot; name=&quot;fileName&quot;>
</form>

<cfset theDirLocal = &quot;\\tm46\C$\Inetpub\<cfset theDirRemote = &quot;\\Ntneas1\chrisdev\upload_cf\folder2\&quot;>


<!--- File Transfer Code Begin --->
<cfif isDefined(&quot;FORM.doTransfer&quot;) AND isDefined(&quot;FORM.fileName&quot;)>
<cfset seeThis = #FORM.doTransfer# & #FORM.fileName#>

<!--- <cffile action=&quot;upload&quot;
filefield=&quot;#FORM.fileName#&quot;
nameconflict=&quot;overwrite&quot;
destination=&quot;#theDirRemote#&quot;> --->

<cfelse>
<cfset seeThis = &quot;No action.&quot;>
</cfif>
<!--- File Transfer Code End --->


<cfdirectory action=&quot;list&quot; directory=&quot;#theDirLocal#&quot; name=&quot;theListLocal&quot; sort=&quot;name&quot;>
<cfdirectory action=&quot;list&quot; directory=&quot;#theDirRemote#&quot; name=&quot;theListRemote&quot; sort=&quot;name&quot;>



<table width=&quot;98%&quot; bgcolor=&quot;#EEEEEE&quot;>
<tr class=&quot;size2&quot;>
<td colspan=&quot;2&quot;><cfoutput>#seeThis#</cfoutput>
</td></tr>
<tr><td width=&quot;50%&quot; valign=&quot;top&quot;>

<cfset numItem = 0>
<!--- Local Dir Start --->
<table border=&quot;1&quot; width=&quot;100%&quot;>
<!--- Header Rows --->
<tr class=&quot;size2bold&quot; valign=&quot;top&quot;>
<cfoutput><td colspan=&quot;4&quot;>#theDirLocal#</td></cfoutput>
</tr>
<tr class=&quot;size2bold&quot; valign=&quot;top&quot;>
<td>N </td><td>File Name</td><td>File Name 2</td><td>File Size</td>
</tr>
<!--- Header Rows --->

<cfoutput query=&quot;theListLocal&quot;>
<tr class=&quot;size2&quot;>
<!--- Number on list --->
<cfset numItem = numItem + 1>
<td align=&quot;right&quot; width=&quot;8%&quot;>#numItem#</td>

<!--- File Name --->
<cfset theFolder = &quot;&quot;>
<cfset theFileName = #name#>
<cfset theFullName = #theDirLocal# & #theFileName#>
<td><a href=#theFullName#>#theFileName#</a></td>
<td><a href=&quot;javascript:AddToList('#theFileName#')&quot;>#theFileName#</a></td>

<!--- File Size --->
<cfset sizeB = #size#>
<cfif sizeB gt 1024 >
<cfset sizeKB = DecimalFormat(sizeB/1024)>
<cfif sizeKB gt 1024 >
<cfset sizeMB = DecimalFormat(sizeKB/1024)>
<cfset theSizeDis = sizeMB & &quot; MB&quot;>
<cfelse>
<cfset theSizeDis = sizeKB & &quot; KB&quot;>
</cfif>
<cfelse>
<cfset theSizeDis = sizeB & &quot; B&quot;>
</cfif>
<td align=&quot;right&quot;>#theSizeDis#</td>
</tr>
</cfoutput>
</table>
<!--- Local Dir Start --->
</td>
<td valign=&quot;top&quot;>
<cfset numItem = 0>
<!--- Remote Dir Start --->
<table border=&quot;1&quot; width=&quot;100%&quot;>
<!--- Header Rows --->
<tr class=&quot;size2bold&quot; valign=&quot;top&quot;>
<cfoutput><td colspan=&quot;4&quot;>#theDirRemote#</td></cfoutput>
</tr>
<tr class=&quot;size2bold&quot; valign=&quot;top&quot;>
<td>N </td><td>File Name</td><td>File Name 2</td><td>File Size</td>
</tr>
<!--- Header Rows --->

<cfoutput query=&quot;theListRemote&quot;>
<tr class=&quot;size2&quot;>
<!--- Number on list --->
<cfset numItem = numItem + 1>
<td align=&quot;right&quot;>#numItem#</td>

<!--- File Name --->
<cfset theFolder = &quot;&quot;>
<cfset theFileName = #name#>
<cfset theFullName = #theDirRemote# & #theFileName#>
<td><a href=#theFullName#>#theFileName#</a></td>
<td><a href=&quot;javascript:AddToList('#theFileName#')&quot;>#theFileName#</a></td>

<!--- File Size --->
<cfset sizeB = #size#>
<cfif sizeB gt 1024 >
<cfset sizeKB = DecimalFormat(sizeB/1024)>
<cfset theSizeDis = sizeKB & &quot; KB&quot;>
<cfelse>
<cfset theSizeDis = sizeB & &quot; B&quot;>
</cfif>
<td align=&quot;right&quot;>#theSizeDis#</td>
</tr>
</cfoutput>
</table>
<!--- Remote Dir Start --->
</td></tr>

</table>
</body>
</html>


******************************************************
 
You must use a <input type=&quot;file&quot;> and let the user select the file they want to upload. This is the only way to upload a file. Once the user selects the file you cannot manipulate the name on the client side, and you cannot change the file they have selected. This is done to prevent people from uploading files from the user that they are not supposed to be getting. This way the user knows every file transfer that they are taking part in.

So to make a long story short, the way you are trying to upload files is impossible (unless i'm mistaken, which happens quite often).

Rackboyut
 
Code:
<cfset theDirLocal = &quot;\\tm46\C$\Inetpub\[URL unfurl="true"]wwwroot\2upload\&quot;>[/URL]
<cfset theDirRemote = &quot;\\Ntneas1\chrisdev\upload_cf\folder2\&quot;>
Does ColdFusion have permissions to access these remote directories? If the CF Services are still running under the default setup, then they only have permissions on the local machine. Try changing the directory to something on your local machine (C:\Inetpub\ just to see if it works.



Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Ecobb,
Yes, ColdFusion does have permission to access the remote directories. The <cfdir>'s can display the contents of what I supplied. Guess, I'll try out the custom tag.

Rackboyut,
Well, I was afraid you were gonna say that... but at least I know now. I don't suppose you can by any chance preset <input type=&quot;file&quot;> so my user doesn't have to browse repeated.

Thank you both for your time,
Chris
 
Unfortunately you cannot edit the data in that field, and you cannot state where to start the browse. There are some Java applets available that allow you to do this, but i cannot remember the name of them right off the top of my head. Ill try to find them later tonight and send you a link.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top