Solved

ColdFusion Need help with download file/s function

Posted on 2013-12-11
7
413 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

623 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