Solved

ColdFusion Need help with download file/s function

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now