Provides additional information to the cfzip tag.
The cfzipparamtag is always a child tag of the cfzip tag.
ColdFusion 11: Added 2 new attributes, password and encryptionalgorithm.
ColdFusion 8: Added this tag.
<cfzipparam charset = "encoding type" content = "variable name" entryPath = "full pathname" filter = "file filter" prefix = "string" recurse = "yes|no" source = "source directory" encryptionAlgorithm = "standard|AES-128|AES-256" password = "password string">
You can specify this tag’s attributes in anattributeCollectionattribute whose value is a structure. Specify the structure name in theattributeCollectionattribute and use the tag’s attribute names as structure keys.
cfzipparam(charset = "encoding type", content = "variable name", entryPath = "full pathname", filter = "file filter", prefix = "string", recurse = "yes|no", source = "source directory", encryptionAlgorithm = "standard|AES-128|AES-256", password = "password string")
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 whencfzip action="zip"and thecfzipparamcontent is a string. Examples of character sets:
|
content |
Optional |
Content written to the ZIP or JAR entry. Used only whencfzip action="zip". Valid content data types arebinaryandstring. If you specify thecontentattribute, specify theentrypathattribute. |
|
entryPath |
Optional |
Pathname used:
|
|
filter |
Optional |
File filter applied to the action. For example, for thezipaction, all the files in thesourcedirectory that match the filter are zipped. |
|
prefix |
Optional |
String added as a prefix to the ZIP or JAR entry. Used only whencfzip action="zip". |
|
recurse |
Optional |
yes |
Include the directory to be zipped, unzipped, or deleted, as specified by thecfzipparent tag. |
source |
Optional |
Source directory or file. Used only whencfzip action="zip". Specified files are added to the ZIP or JAR file:
|
|
encryptionAlgorithm | Optional | The encryption algorithm to use for compression. The following options are valid:
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. |
|
password | read readBinary zip unzip | Required, if encryptionAlgorithm is specified | The password to protect the archive. |
Use thecfzipparamtag with thecfziptag to zip, extract, or delete multiple files or directories. For example, to zip multiple directories, specify acfzipparamtag for each source directory.
<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>
<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>
<!--- 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>
<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>
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:
<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:
<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>
To protect a zip archive with a password:
<cfzip action="zip" file="<zip_file_path>" source="<source_dir_path>" password="admin" encryptionAlgorithm="AES-128" /> <cfzip action="unzip" file="<zip_file_path>" destination="<dest_dir_path>" > <cfzipparam entrypath="sample.txt" password="admin" encryptionAlgorithm="AES-128"> </cfzip>
Sign in to your account