Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ColdFusion Need help with download file/s function

Posted on 2013-12-11
7
Medium Priority
?
414 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 2000 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

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

688 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