Solved

ColdFusion Need help with download file/s function

Posted on 2013-12-11
7
411 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
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.

752 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