Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ColdFusion Need help with download file/s function

Posted on 2013-12-11
7
408 Views
Last Modified: 2013-12-20
The code below does the following:
For each record checked it will look inside a folder (each record has a folder) and download the file. Users can click one or many records to download. The download to a zip folder function runs after this code and is not shown.

How can I add the functionality of downloading all files (in each folder/record) instead of just one file? If I place 2 PDF's in one of these folders, only one will be downloaded.
Do I need to create a loop within a loop?


<CFLOOP INDEX=j FROM=1 TO=#ArrayLen(myarray)#>
	<CFSET ChkDir="\\DSS1\Shared_Data\325\DDA\www\tasks\#myarray[j]#\NUL">
	<CFIF #FileExists(chkdir)# eq 0>  <!--- Set to 0 because this function isn't working -=DOES A FOLDER EXIST FOR THIS DOCUMENT?  --->
		<CFDIRECTORY DIRECTORY="\\DSS1\Shared_Data\325\DDA\www\tasks\#myarray[j]#" NAME="tiidquery" filter="*.pdf" SORT="name ASC">
		<CFIF #TIIDQUERY.RecordCount# GT 0>  <!---  ARE THERE ANY .PDF FILES IN THE FOLDER --->
			<cfset downloadable="yes">
			<CFQUERY NAME="QUERY" DATASOURCE="Web_dd">
			SELECT DISTINCT * FROM DD_TASKINFO WHERE TI_ID=#myarray[j]#
			</CFQUERY>
			<CFSET TIIDNAME=#SpanExcluding(tiidquery.name,".")#>
			<CFSET JMX_DocNumber=#TRIM(tiidname)#>
			<CFSET JMX_DocumentSize="A">
			<CFOUTPUT QUERY="QUERY">
				<CFSET JMX_DocRevision=#Trim(ti_rev)#>
				<CFSET JMX_DocumentTitle=Left("#Trim(ti_brief)#",40)>
			</CFOUTPUT>
			<CFLOOP QUERY=TIIDQUERY>
				
                        <CFIF find(".PDF","#UCASE(NAME)#") NEQ 0>
	<CFDIRECTORY ACTION="create" DIRECTORY="c:\dwgbin\#DLname#\#tiidname#">
<CFFILE ACTION="Copy" SOURCE="\\DSS1\Shared_Data\325\DDA\www\tasks\#myarray[j]#\#name#" DESTINATION="c:\dwgbin\#DLname#\#tiidname#\">

Open in new window

0
Comment
Question by:DJPr0
  • 2
  • 2
7 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 39712513
AFAIK, you can't. HTTP requests don't work that way.  They're designed to send a single file/filetype (normally). I read somewhere it might be possible by exploiting multi-part headers, but even if did work... browser support would be spotty at best. Your best bet is to stick w/a single zip file. That's the standard solution to the single file limitation.
0
 

Author Comment

by:DJPr0
ID: 39712746
I am looking for a singe zipped file. The current CF code just extracts 1 file in each folder.

The existing operation:
The user checks the boxes of desired records - CF looks inside each folder and extracts the file (1 - PDF) and zips them up, then a download button is displayed.

Works great.

Modified desired operation:
The user checks the boxes of desired records - CF looks inside each folder and extracts the file/s (1 or more - PDF's) and zips them up, then a download button is displayed.
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 39722928
Basic example:

You want to zip the following 3 files into 1 zip file.
<cfset files="d:\files\images\img1.png,d:\files\docs\doc1.docx,d:\files\pdfs\pdf1.pdf">

Where to save your zip file
<cfset filename="d:\files\zips\myzipfile.zip">

<cfset overwrite=1>
<cfloop list="#variables.files#" index="ii">

      <cfzip
            source="#ii#"  
            action="zip"
            overwrite="#variables.overwrite#"
            file="#variables.filename#">

<cfset overwrite=0>
</cfloop>
You'll now have 1 zip file that contains the 3 files from the variable files.

So the concept is to do your preliminary work grabbing your filepath + filename for all files you want to zip.
Then run code similar to this and that's pretty much it.

good luck ...
0
 

Author Closing Comment

by:DJPr0
ID: 39732165
Thanks  dgrafx!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39732173
np ...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question