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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to create 1 form surrounding multiple file upload fields 2

Status
Not open for further replies.

chlebicki

Technical User
Jul 4, 2006
31
US
Hi,

I am trying to create a dynamic table with multiple rows, with a file upload field inserted so each file upload field is assigned to a product ID. One form and one submit button surround all of this, where upon submitting, each file upload field uploads its respective file to its respective directory.

Any suggestions? Right now I have the upload field nested in the dynamic table. When I try to upload more than one file it will only upload the first file in the dynamic table – skipping over the remaining file fields.

Thanks,
Craig
 
How are you assigning a product ID to a corrosponding file field?

you can name the file field like:
file_1
file_2
file_3
file_4

and a corrosponding hidden field like:
pid_1 value= 123
pid_2 value= 36
pid_3 value= 100
pid_4 value= 6

and a final hidden field that will keep track of how many file / product ID's there are in the dynamic form

fileCount value=4

than loop through them on the action page.

loop from 1 to form.fileCount index=i

filefield = "form.file_" & i (for cffile)
file = form["file_" & i] (for cffile)
pid = form["pid_" & i] (for queries to match file to product)

upload file
insert / update db
done.


Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Kevin,

Thanks for the code. I think I found a work around, but while it works it definitely is not as stream-lined as yours. I am going to print it out and try to get your idea, as it doesn't require as much hard-coding.

One of the last parts of my website that I can't figure out it how to automatically rename a file upon uploading. I have done a lot of websearching and found some info, but none answered the question on how to upload and rename (to a variable) at the same time if you have multiple types (jpeg, avi, mov..) of files being uploaded. Any ideas?

Nice website, I going to go through it to learn more about cf as I have only been working with cf for about 2 months now.

Cheers,
Craig

ps- is your signature a South Park reference?
 
I wrote up a multiple file upload tutorial after I answered your question, it has more real code and might help more



check cffile action="rename" to change the name of a file after it is uploaded. So during the loop on the action page, you use cffile to upload the file, then immediatly use cffile again to rename it.


Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
I wrote up a multiple file upload tutorial after I answered your question, it has more real code and might help more



check cffile action="rename" to change the name of a file after it is uploaded. So during the loop on the action page, you use cffile to upload the file, then immediatly use cffile again to rename it.

ps- is your signature a South Park reference?

yes, a poor one!

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Kevin,

Thanks for your tutorial! I am working on it now. For the renaming tag, the issue I am having is what if I don't know the exact type of file the user is uploading? Here is a passage from a website I read:

---------------------------------------------------------
Renaming Files As They Are Uploaded (how CFFILE actually works)
When receiving a file uploaded from a client, you can actually save it and rename it all in one step rather than two steps as the documentation implies.

The documentation states that the "destination" attribute of the CFFILE tag specifies the "pathname of the directory in which to upload the file." This is misleading for two reasons:

The file has actually already been uploaded by the time your CFFILE tag is encountered. The file has automatically been saved in ColdFusion's temporary directory. Using the CFFILE tag with the action attribute set to "upload" is really just moving the file from one place to another. If no CFFILE tag is encountered, the file is simply deleted.
You can actually specify a file name in addition to a directory in the destination attribute. Rather than this...

<cffile action="upload" destination="/path/to/some/directory" ... />
<cffile action="rename" ... />
... you can just do this...

<cffile action="upload" destination="/path/to/some/directory/#createUUID()#.gif" ... />
---------------------------------------------------------

That assumes you know the file is a .gif, but what if it can also be a jpeg, avi, or .mov? How do you dynamically change that variable?

Thanks again for your help! I have just started to use this board and everyone here has been awesome.

Cheers,
Craig
 
Kevin,

I have realized the coldfusion statement

<cffile action="upload"destination="/path/to/some/directory/#createUUID()#.gif" ... />

doesn't care what type of file it is, but it creates a directory within a directory. So if I am uploading the file "egg.jpg" to "/desktop/folder" the above code inserts "egg.jpg" into the directory "/desktop/folder/#variable#/egg.jpg"

It doesn't appear to change the file's name, but instead inserts the file into a new subdirectory.

~Craig
 
I have read a lot obout cffile and know about the http upload to the temp file, etc... never messed around alot with renaming though.

maybe I'll play around with it later and see what can be done / find a new trick maybe?

for now the 2 step upload / rename will probably work out the best for you.

read up here if you have not already

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
If you are running 701 or under, there is a glitch in the upload process that causes a directory to be created based on the file name you are trying to force, rather than simply renaming the file.

This is an acknowledged issue by MM/Adobe and there is a Hotfix available.


Your issue is #61212

Applying the hotfix should fix the issue (it did for us).




I have not tested the 702 updater yet to see if it was included in that patch.
 
Thanks! Like I said before, this is the best board for CF stuff I have found on the net.

~Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top