Ask a Question related to Macromedia ColdFusion, Design and Development.
-
StylusDesigns #1
Upload Multiple Files in one form
I am trying to upload the track information for cd's, and also upload the audio
sample files at the same time. The samples are real media at this point (not my
choice) but...anyways...
I have a page that asks how many tracks? then the next page takes that and
creates the input box's for track numbers track names and file input fields. I
am attaching the code I have so far, that I cannot get to work. I am not sure
where to go from here. I am not able to able to get the right name of the
sample to the database or get the file to upload to the directory.
<cfloop from="1" to="#form.numba#" index="idx">
<cfset gettrack_number = evaluate("form.track_number" & idx)>
<cfset gettrack_name = evaluate("form.track_name" & idx)>
<cfset getsample_file = evaluate("file.ServerFileName" & idx)>
<cfquery name="data" datasource="klaritymusic">
insert into tracks (album_id,track_number,track_name,sample)
values
(#form.album_id#,#gettrack_number#,'#gettrack_name #','#getsample_file#')
</cfquery>
</cfloop>
<cfloop from="1" to="#form.numba#" index="idx">
<cfset GetSample = evaluate("file" & idx)>
<CFFILE ACTION="upload"
FILEFIELD="#GetSample#"
DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
NAMECONFLICT="MAKEUNIQUE">
</cfloop>
StylusDesigns Guest
-
Multiple Image Upload Form w. Flash
I need to build a form to allow users to upload many image files all from the same page. Can Flash be used to do this? If so, please tell me what... -
upload multiple files
Hi, I have the form where user can upload max to three files at the same time. Also the file is need to be overrtie if user try to post the same... -
upload multiple files is this possible?
Hi guys! is this possible to upload a whole directory or at least all files in a directory at once ? I know how to do it with 10 files then you... -
Multiple upload files with php
Hi, I need to upload multiples files using php, but with the same "<input>" tag, somebody can help my, is this feature supported by php?. Anyboy... -
multiple files upload
Hi Group, In my program, the user has to be able to add one or more documents (as files) for one product from the database. The number of files... -
forumnotifier #2
Upload Multiple Files in one form
I am trying to upload the track information for cd's, and also upload the audio
sample files at the same time. The samples are real media at this point (not my
choice) but...anyways...
I have a page that asks how many tracks? then the next page takes that and
creates the input box's for track numbers track names and file input fields. I
am attaching the code I have so far, that I cannot get to work. I am not sure
where to go from here. I am not able to able to get the right name of the
sample to the database or get the file to upload to the directory.
<cfloop from="1" to="#form.numba#" index="idx">
<cfset gettrack_number = evaluate("form.track_number" & idx)>
<cfset gettrack_name = evaluate("form.track_name" & idx)>
<cfset getsample_file = evaluate("file.ServerFileName" & idx)>
<cfquery name="data" datasource="klaritymusic">
insert into tracks (album_id,track_number,track_name,sample)
values
(#form.album_id#,#gettrack_number#,'#gettrack_name #','#getsample_file#')
</cfquery>
</cfloop>
<cfloop from="1" to="#form.numba#" index="idx">
<cfset GetSample = evaluate("file" & idx)>
<CFFILE ACTION="upload"
FILEFIELD="#GetSample#"
DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
NAMECONFLICT="MAKEUNIQUE">
</cfloop>
forumnotifier Guest
-
StylusDesigns #3
Re: Upload Multiple Files in one form
I made some headway, but I still cannot get the correct data into the database,
but I can get the songs to upload.
here is the code:
--------------------------------------------------------------------------------
-------------------------------------------------------------------------
<cfloop from="1" to="#form.numba#" index="idx">
<cfset gettrack_number = evaluate("form.track_number" & idx)>
<cfset gettrack_name = evaluate("form.track_name" & idx)>
<cfset sample = evaluate('form.sample' & idx)>
<cfquery name="data" datasource="klaritymusic">
insert into tracks (album_id,track_number,track_name,sample)
values (#form.album_id#,#gettrack_number#,'#gettrack_name #','#sample#')
</cfquery>
</cfloop>
<cfset sample = 'sample'>
<cfloop from="1" to="#form.numba#" index="idx">
<cfif (IsDefined("FORM.sample#idx#")) AND (#Evaluate("FORM.sample#idx#")# neq
"")>
<cffile
action="upload"
filefield="sample#idx#"
DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
NAMECONFLICT="MAKEUNIQUE">
</cfif>
</cfloop>
--------------------------------------------------------------------------------
--------------------------------------------------------------------
In the database the sample is listed as "sample
D:\CFusionMX\runtime\servers\default\SERVER-INF\temp\wwwroot-tmp\neotmp45401.tmp
" instead of the file name.
Please Help.
StylusDesigns Guest
-
The ScareCrow #4
Re: Upload Multiple Files in one form
I have attached some quick code I put together (untested)
But basically you need to process each file form field (file upload) seperately
See attached code
Ken
<!--- The form page --->
<form action="action_page.cfm" method="post" enctype="multipart/form-data"
name="form1" id="form1">
<!--- Need to know how may form fields to process, also need to pass this onto
the action page --->
<input type="hidden" name="form.numba"
value="<cfoutput>#form.numba#</cfoutput>">
<cfloop from="1" to="#form.numba#" index="idx">
<input type="text" name="track_name#idx#">
<input type="file" name="track#idx#">
</cfloop>
<input type="submit" name="submit" value="Upload">
</form>
<!--- The action page --->
<cfloop from="1" to="#form.numba#" index="idx">
<!--- process each file upload seperately --->
<!--- upload the file(s) --->
<CFFILE ACTION="upload"
FILEFIELD="#form['track' & idx]#"
DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
NAMECONFLICT="MAKEUNIQUE">
<!--- insert the record into data base --->
<cfquery name="data" datasource="klaritymusic">
insert into tracks (album_id,track_number,track_name,sample)
values (#form.album_id#,#gettrack_number#,'#form["track_name" &
idx]#','#ServerFileName#')
</cfquery>
</cfloop>
The ScareCrow Guest
-
StylusDesigns #5
Re: Upload Multiple Files in one form
I could not get the code to work that was recommended,
here is what I have now
<cfloop from="1" to="#form.numba#" index="idx">
<cfif (IsDefined("FORM.sample#idx#")) AND (#Evaluate("FORM.sample#idx#")# neq
"")>
<cffile action="upload" filefield="sample#idx#"
DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
NAMECONFLICT="MAKEUNIQUE">
</cfif>
<cfset gettrack_number = evaluate("form.track_number" &
idx)>
<cfset gettrack_name = evaluate("form.track_name" & idx)>
<cfset getsample_name = '#cffile.ServerFileName#'>
<cfquery name="data" datasource="klaritymusic">
insert into tracks (album_id,track_number,track_name,sample)
values
(#form.album_id#,#gettrack_number#,'#gettrack_name #','#getsample_name#')
</cfquery>
</cfloop>
I am stuck on the cffile.serverfilename cannot get it to return a value. The
error message I get is "Element SERVERFILENAME is undefined in CFFILE. "
Thanks
StylusDesigns Guest
-
The ScareCrow #6
Re: Upload Multiple Files in one form
The attached code is a working example.
While it did not insert a record into a table, it does output the sql
statement, which is correct if the other (column) values are supplied.
All you need to do is copy the 3 pages and save them and run. Once you
understand what the code is doing, then change it to meet your needs
Ken
PAGE ONE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="page2.cfm" method="post" name="form1" id="form1">
<p>Please select how many files to upload</p>
<p>
<select name="numba">
<cfloop from="1" to="10" index="idx">
<cfoutput>
<option value="#idx#">#idx#</option>
</cfoutput>
</cfloop>
</select>
</p>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
PAGE TWO
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="page3.cfm" method="post" enctype="multipart/form-data"
name="form2" id="form2">
<!--- Need to know how may form fields to process, also need to pass this onto
the action page --->
<input type="hidden" name="numba" value="<cfoutput>#form.numba#</cfoutput>">
<cfoutput>
<cfloop from="1" to="#form.numba#" index="idx">
<input type="text" name="track_name#idx#"> <input type="file"
name="track#idx#"><br>
</cfloop>
</cfoutput>
<input type="submit" name="submit" value="Upload">
</form>
</form>
</body>
</html>
PAGE THREE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<!--- The action page --->
<cfloop from="1" to="#form.numba#" index="idx">
<!--- process each file upload seperately --->
<!--- upload the file(s) --->
<cfset field = "track#idx#">
<cffile action="UPLOAD" filefield="#field#"
destination="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples" result=""
nameconflict="MAKEUNIQUE">
<!--- insert the record into data base --->
<!--- <cfquery name="data" datasource="klaritymusic"> --->
<cfoutput>
insert into tracks (album_id,track_number,track_name,sample)
values (form.album_id,gettrack_number,'#form["track_name" &
idx]#','#cffile.serverFile#')
</cfoutput>
<!--- </cfquery> --->
</cfloop>
</body>
</html>
The ScareCrow Guest
-
StylusDesigns #7
Re: Upload Multiple Files in one form
Thank you very much for the code & help. I did get it to work, I used your
code, I taylored it a little bit to fit, then realized my errors which I don't
think I mentioned to you that only some of the tracks get a sample file, not
all. So when it was coming back and saying that it couldn't find the
cffile.serverfilename thats because I didn't submit a file. I setup a cfif
cfelse to cover that problem, and it works great now.
Thanks Again, I attached the final code that made it work.
<!--- The action page --->
<cfloop from="1" to="#form.numba#" index="idx">
<!--- process each file upload seperately --->
<!--- upload the file(s) --->
<cfset field = "track#idx#">
<cfif (IsDefined("#field#")) AND (#Evaluate("#field#")# neq "")>
<cffile action="UPLOAD" filefield="#field#"
destination="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
nameconflict="MAKEUNIQUE">
<!--- insert the record into data base --->
<cfquery name="data" datasource="klaritymusic">
<cfoutput>
insert into tracks (album_id,track_number,track_name,sample)
values (#form.album_id#,#form["track_number" &
idx]#,'#form["track_name" & idx]#','#cffile.serverFile#')
</cfoutput>
</cfquery>
<cfelse>
<cfquery name="data" datasource="klaritymusic">
<cfoutput>
insert into tracks (album_id,track_number,track_name)
values (#form.album_id#,#form["track_number" &
idx]#,'#form["track_name" & idx]#')
</cfoutput>
</cfquery>
</cfif>
</cfloop>
StylusDesigns Guest



Reply With Quote

