Your Rating: Results: PatheticBadOKGoodOutstanding! 32 rates

Description

Manipulates ZIP and Java Archive (JAR) files. In addition to the basic zip and unzip functions, use the cfzip tag to delete entries from an archive, filter files, read files in binary format, list the contents of an archive, and specify an entry path used in an executable JAR file.

History

ColdFusion 11: Added 2 new attributes, password and encryptionalgorithm.

ColdFusion 8: Added this tag.

Category

File management tags

Syntax

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

cfzipparam

Attributes

Attribute

Action

Req/Opt

Default

Description

action

N/A

Optional

zip

Action to take. Must be one of the following:

  • delete
  • list
  • read
  • readBinary
  • unzip
  • zip
    If you do not specify an action, ColdFusion applies the default action, zip.

charset

read

Optional

default encoding of the host machine

Character set used to translate the ZIP or JAR entry into a text string. Examples of character sets:

  • JIS
  • RFC1345
  • UTF-16

destination

unzip

Required

 

Destination directory where the ZIP or JAR file is extracted.

entryPath

deletereadreadBinaryunzip

Optional

 

Pathname on which the action is performed.

file

deletelistreadreadBinaryunzipzip

Required

 

Absolute pathname of the file on which the action is performed; for example, the full pathname of the ZIP file: c:\temp\log.zip.
If you do not specify the full pathname (for example, file="log.zip"), ColdFusion creates the file in a temporary directory. You can use the GetTempDirectory function to access the ZIP or JAR file.

filter

deletelistunzipzip

Optional

 

File filter applied to the action. The action applies to all files in the specified pathname that match the filter.

name

list

Required

 

Record set name in which the result of the list action is stored. The record set columns are the following:

  • name: Filename of the entry in the JAR file. For example, if the entry is help/docs/index.htm, the name is index.htm.
  • directory: Directory containing the entry. For the preceding example, the directory is help/docs. You can obtain the full entry name by concatenating directory and name. If an entry is at the root level, the directory is empty (" ").
  • size: Uncompressed size of the entry, in bytes.
  • compressedSize: Compressed size of the entry, in bytes.
  • type: Type of entry (directory or file).
  • dateLastModified: Last modified date of the entry, cfdate object.
  • comment: Any comment, if present, for the entry.
  • crc: Crc-32 checksum of the uncompressed entry data.

overwrite

unzipzip

Optional

no

unzip: Specifies whether to overwrite the extracted files:

  • yes: If the extracted file exists at the destination specified, the file is overwritten.
  • no: If the extracted file exists at the destination specified, the file is not overwritten and that entry is not extracted. The remaining entries are extracted.
    zip: Specifies whether to overwrite the contents of a ZIP or JAR file:
  • yes: Overwrites all of the content in the ZIP or JAR file if it exists.
  • no: Updates existing entries and adds new entries to the ZIP or JAR file if it exists.

prefix

zip

Optional

 

String added as a prefix to the ZIP or JAR entry. The string is the name of a subdirectory in which the entries are added.

recurse

deletelistunzipzip

Optional

yes

Specifies whether the action applies to subdirectories:

  • yes: Includes subdirectories.
  • no: Does not include subdirectories.

showDirectory

list

Optional

no

Specifies whether to show the directory structure:

  • yes: Lists the directories.
  • no: Does not list directories.

source

zip

Required (see description)

 

Source directory to be zipped. Not required if the cfzipparam tag is specified.

storePath

unzipzip

Optional

yes

unzip: Specifies whether files are stored at the entry path:

  • yes: The files are extracted to the entry path.
  • no: The entry path is ignored and all the files are extracted at the root level.
    zip: Specifies whether pathnames are stored in the ZIP or JAR file:
  • yes: Pathnames of entries are stored in the ZIP or JAR file.
  • no: Pathnames of the entries are not stored in the ZIP or JAR file. All the files are placed at the root level. In case of a name conflict, the last file in the iteration is added.

variable

readreadBinary

Required

 

Variable in which the content is stored.

passwordzipOptional The password to be used for the archive.
encryptionAlgorithmzipOptional 

The encryption algorithm to use for compression. The following options are valid:

  • AES-256
  • AES-128
  • Standard


If the attibutes are specified in the CFZip tag, they can be inherited or overridden by the corresponding attributes in the CFZipparam tag.

If only password is provided, the default encryptionAlgorithm will be AES 256-bit.

If used with a directory, all files in that directory will be protected with the same password/encryption.

Usage

Use the cfzip tag to zip and unzip files and manipulate existing ZIP or JAR files in ColdFusion. You can use the cfzip tag independently or with one or more cfzipparam tags to manipulate multiple files or directories. The cfzip tag is the parent tag of the cfzipparam tag.
The ZIP format is the standard format for file archiving and compression. The JAR format is based on the ZIP format. JAR files are platform-independent.

Note

The cfzip tag does not create directories. If you specify a directory that does not exist, ColdFusion generates an error.

Use the following syntax to specify an in-memory file or directory in any attribute that takes a path. In-memory files are not written to disk and speed processing of transient data.

The filepath can include multiple directories, for example ram:///petStore/images/dogImages.zip. You must create the directories in the path before you specify the file. For more information on using in-memory files, see Working with in-memory files in Optimizing ColdFusion applications in the Developing ColdFusion Applications.

delete action

Use the delete action to delete entries from a ZIP or JAR file.

list action

Use the list action to list the entries of a ZIP or JAR file. The following table shows the types of information you can retrieve for entries in the archive:

Field

Description

comment

Text string description saved with the entry source.

compressedSize

Compressed size of the entry in bytes.

crc

Checksum for the entry source.

dateLastModified

Date and time when the source was last modified.

directory

Name of the directory where the entry is stored.

name

Entry pathname.

size

Uncompressed size of the entry source in bytes.

type

Source type for the entry, for example, file.

You can use the cfdump tag to list all of the information in a ZIP or JAR file, as the following example shows:

You can use the cfoutput tag to list individual fields for the entries in an archive, as the following example shows:

read action

Use the read action to read the content of the ZIP or JAR file entry in human-readable format. The read action uses the charset value to create the string.

readBinary action

Use the readBinary action to read the content of a ZIP or JAR file in binary format.

unzip action

Use the unzip action to extract the entries from a ZIP or JAR file.

zip action

Use the zip action to create or update a ZIP or JAR file. This is the default action; you do not have to specify it explicitly. If you specify a ZIP or JAR file that does not exist, ColdFusion creates it. If the ZIP or JAR file exists, ColdFusion adds new entries from the source and updates existing entries if they have changed. If you set the overwrite attribute to yes, all of the entries in the ZIP or JAR file are replaced by the new content.

Example

The following example shows how to zip 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 first action page displays the images by the selected artist, zips the files, and writes the ZIP file to a temporary directory. Also, it includes a form to e-mail the ZIP file:

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

Labels
  • None
  1. May 04, 2014

    "password" attribute added with CF11 is not listed in the table showing attributes.


Searching ColdFusion, English documentation