cfzipparam

Description

Provides additional information to the cfzip tag.

The cfzipparam tag is always a child tag of the cfzip tag.

History

ColdFusion 8: Added this tag.

Syntax

<cfzip ..> 
    <cfzipparam 
        charset = "encoding type" 
        content = "variable name" 
        entryPath = "full pathname" 
        filter = "file filter" 
        prefix = "string" 
        recurse = "yes|no" 
        source = "source directory"> 
</cfzip>
Note: You can specify this tag’s attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag’s attribute names as structure keys.

See also

cfzip

Attributes

Attribute

Req/Opt

Default

Description

charset

Optional

default encoding of the host machine

Converts string content into binary data before putting it into a ZIP or JAR file. Used only when cfzip action="zip" and the cfzipparam content is a string.

Examples of character sets:

  • JIS

  • RFC1345

  • UTF-16

content

Optional

Content written to the ZIP or JAR entry. Used only when cfzip action="zip".

Valid content data types are binary and string. If you specify the content attribute, specify the entrypath attribute.

entryPath

Optional

Pathname used:

  • For cfzip action="zip", it is the entry path used. This is valid only when the source is a file. The entry path creates a subdirectory in the ZIP or JAR file.

  • For cfzip action="unzip", it is the pathname to unzip.

  • For cfzip action="delete", it is the pathname to delete from the ZIP or JAR file.

filter

Optional

File filter applied to the action. For example, for the zip action, all the files in the source directory that match the filter are zipped.

prefix

Optional

String added as a prefix to the ZIP or JAR entry. Used only when cfzip action="zip".

recurse

Optional

yes

Include the directory to be zipped, unzipped, or deleted, as specified by the cfzip parent tag.

source

Optional

Source directory or file. Used only when cfzip action="zip".

Specified files are added to the ZIP or JAR file:

  • If you specify source attribute for the cfzip tag, the cfzipparam source is relative to it.

  • If you do not specify a source attribute for the cfzip tag, the cfzipparam source must be an absolute pathname.

Usage

Use the cfzipparam tag with the cfzip tag to zip, extract, or delete multiple files or directories. For example, to zip multiple directories, specify a cfzipparam tag for each source directory.

Example

Example 1

<!--- This example shows how to zip class files from one subdirectory and class and property files from another directory into a JAR file. ---> 
<cfzip file="c:\util.jar" source="c:\myproj\classes"> 
    <cfzipparam source="com\abc\util" filter="*.class"> 
    <cfzipparam source="com\abc\io" filter="*.class, *.properties"> 
</cfzip>

Example 2

<!--- This example shows how to update a ZIP file with files from multiple locations, each with a different filter. ---> 
<cfzip file="e:\work\test.jar" action="zip"> 
    <cfzipparam source="c:\temp\abc.txt" prefix="com\abc"> 
    <cfzipparam source="c:\src\classes" recurse="yes" 
            filter="*.class,*.properties" prefix="classes"> 
    <cfzipparam source="c:\src\Manifest.MF" entrypath="META-INF\MANIFEST"> 
</cfzip>

Example 3

<!--- This example shows how to insert the string format for a programmatically generated XML file into a ZIP file. ---> 
<!--- Create a variable that specifies a time-out period. ---> 
<cfset myDoc="<system-config><timeout>1500</timeout><pool-max-size>30 
            </pool-max-size></system-config>"> 
<!--- Zip the file. ---> 
<cfzip file="e:\work\test.zip" action="zip"> 
    <cfzipparam source="c:\src\Manifest.MF" entrypath="META-INF\MANIFEST"> 
    <cfzipparam content="#myDoc#" entrypath="system-config.xml"> 
</cfzip>

Example 4

<!--- This example shows how to update a JAR file with a new version of the file and add some new files to the JAR file. ---> 
<cfzip file="e:\work\admin.jar"> 
    <cfzipparam source="c:\src\classes" recurse="yes"  
            filter="*.class,*.properties"> 
    <cfzipparam source="c:\src\Manifest.MF" entrypath="META-INF\MANIFEST"> 
</cfzip>

Example 5

The following example shows how to zip multiple image files chosen from a form and e-mail the ZIP file to the person requesting the images.

The first ColdFusion page populates a pop-up menu with the names of artists generated from a database query:

<!--- The following code creates a form for selecting images. ---> 
<h3>Select the images</h3> 
<p>Please choose the images you would like sent to you.</p> 
<!--- Create the ColdFusion form to select the images. ---> 
<table> 
<cfform action="zip2_action.cfm" method="post"  
    enctype="multipart/form-data"> 
    <tr> 
        <td><img src="../cfdocs/images/artgallery/elecia01.jpg"/><br/> 
        <cfinput type="checkbox" name="ck1" Value=1>Cube</td> 
        <td><img src="../cfdocs/images/artgallery/elecia02.jpg"/><br/> 
        <cfinput type="checkbox" name="ck2" Value=1>Pentagon</td> 
        <td><img src="../cfdocs/images/artgallery/elecia03.jpg"/><br/> 
        <cfinput type="checkbox" name="ck3" Value=1>Surfer Dude</td> 
        <td><img src="../cfdocs/images/artgallery/elecia04.jpg"/><br/> 
        <cfinput type="checkbox" name="ck4" Value=1>Surfer Girl</td></tr> 
        <tr><td><cfinput type = "Submit" name = "OK" label="OK"></td></tr> 
</table> 
</cfform>

The first action page zips the files selected from the form, and writes the ZIP file to the hard drive. Also, it includes a form to e-mail the ZIP file:

<!--- Determine the absolute pathname on the server. ---> 
<cfset thisDir = ExpandPath(".")> 
 
<!--- Create a ZIP file based on the selections from the form. Use the cfzipparam tag to specify the source for each check box selection. ---> 
<cfzip file="c:\images.zip" source="#thisDir#" action="zip" overwrite="yes"> 
    <cfif IsDefined("form.ck1")> 
        <cfzipparam source="../cfdocs/images/artgallery/elecia01.jpg"> 
        </cfif> 
    <cfif IsDefined("form.ck2")> 
        <cfzipparam source="../cfdocs/images/artgallery/elecia02.jpg"> 
        </cfif> 
    <cfif IsDefined("form.ck3")> 
        <cfzipparam source="../cfdocs/images/artgallery/elecia03.jpg"> 
        </cfif> 
    <cfif IsDefined("form.ck4")> 
        <cfzipparam source="../cfdocs/images/artgallery/elecia04.jpg"> 
        </cfif> 
</cfzip> 
<h3>Mail the ZIP File</h3> 
<p>Please enter your e-mail address so we can send you the ZIP file as an attachment.</p> 
<cfif IsDefined("form.mailto")> 
    <cfif form.mailto is not "" > 
        <cfoutput> 
            <cfmail from="coldfusion@adobe.com" to="#form.mailto#"  
                    subject="see zipped attachment"> 
    The images you requested are enclosed in a ZIP file. 
            <cfmailparam file="#thisDir#/images.zip"> 
            </cfmail> 
        </cfoutput>     
        </cfif> 
    </cfif>     
<cfform action = "zipArt_action2.cfm" method="post"> 
    Your e-mail address: <cfinput type = "Text" name = "MailTo"> 
    <!--- Specify the required field. ---> 
    <cfinput type = "hidden" name = "MailTo_required"  
    value = "You must enter your email address"> 
    <cfinput type = "hidden" name="zipPath" value = "c:\images.zip"> 
    <p><cfinput type = "Submit" name = "OK" label="Mail"> 
</cfform>

The second action page mails the ZIP file as an attachment:

<h3>Mail the ZIP file</h3> 
<p>Your file has been mailed to you.</p> 
<cfset eMail="#form.MailTo#"> 
<cfset zipPath="#form.zipPath#"> 
<cfmail from="coldfusion@adobe.com" to="#eMail#" 
    subject="see zipped attachment"> 
    The images you requested are enclosed in a ZIP file. 
    <cfmailparam file="#zipPath#"> 
</cfmail>