<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Set the encryption method of an entry defined by its name</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ziparchive.setencryptionindex.html">ZipArchive::setEncryptionIndex</a></div> <div class="next" style="text-align: right; float: right;"><a href="ziparchive.setexternalattributesindex.html">ZipArchive::setExternalAttributesIndex</a></div> <div class="up"><a href="class.ziparchive.html">ZipArchive</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="ziparchive.setencryptionname" class="refentry"> <div class="refnamediv"> <h1 class="refname">ZipArchive::setEncryptionName</h1> <p class="verinfo">(PHP >= 7.2.0, PECL zip >= 1.14.0)</p><p class="refpurpose"><span class="refname">ZipArchive::setEncryptionName</span> — <span class="dc-title">Set the encryption method of an entry defined by its name</span></p> </div> <div class="refsect1 description" id="refsect1-ziparchive.setencryptionname-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>ZipArchive::setEncryptionName</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$method</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span> ] )</div> <p class="para rdfs-comment"> Set the encryption method of an entry defined by its name. </p> </div> <div class="refsect1 parameters" id="refsect1-ziparchive.setencryptionname-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">name</code></dt> <dd> <p class="para"> Name of the entry. </p> </dd> <dt> <code class="parameter">method</code></dt> <dd> <p class="para"> The encryption method defined by one of the ZipArchive::EM_ constants. </p> </dd> <dt> <code class="parameter">password</code></dt> <dd> <p class="para"> Optional password, default used when missing. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-ziparchive.setencryptionname-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-ziparchive.setencryptionname-examples"> <h3 class="title">Examples</h3> <p class="para"> This example creates a ZIP file archive <var class="filename">test.zip</var> and add the file <var class="filename">test.txt</var> encrypted using the AES 256 method. </p> <div class="example" id="example-895"> <p><strong>Example #1 Archive and encrypt a file</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$zip </span><span style="color: #007700">= new </span><span style="color: #0000BB">ZipArchive</span><span style="color: #007700">();<br />if (</span><span style="color: #0000BB">$zip</span><span style="color: #007700">-></span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.zip'</span><span style="color: #007700">, </span><span style="color: #0000BB">ZipArchive</span><span style="color: #007700">::</span><span style="color: #0000BB">CREATE</span><span style="color: #007700">) === </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$zip</span><span style="color: #007700">-></span><span style="color: #0000BB">setPassword</span><span style="color: #007700">(</span><span style="color: #DD0000">'secret'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$zip</span><span style="color: #007700">-></span><span style="color: #0000BB">addFile</span><span style="color: #007700">(</span><span style="color: #DD0000">'text.txt'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$zip</span><span style="color: #007700">-></span><span style="color: #0000BB">setEncryptionName</span><span style="color: #007700">(</span><span style="color: #DD0000">'text.txt'</span><span style="color: #007700">, </span><span style="color: #0000BB">ZipArchive</span><span style="color: #007700">::</span><span style="color: #0000BB">EM_AES_256</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$zip</span><span style="color: #007700">-></span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /> echo </span><span style="color: #DD0000">"Ok\n"</span><span style="color: #007700">;<br />} else {<br /> echo </span><span style="color: #DD0000">"KO\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-ziparchive.setencryptionname-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="methodname"><a href="ziparchive.setpassword.html" class="methodname" rel="rdfs-seeAlso">ZipArchive::setPassword()</a> - Set the password for the active archive</span></li> <li class="member"><span class="methodname"><a href="ziparchive.setencryptionindex.html" class="methodname" rel="rdfs-seeAlso">ZipArchive::setEncryptionIndex()</a> - Set the encryption method of an entry defined by its index</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ziparchive.setencryptionindex.html">ZipArchive::setEncryptionIndex</a></div> <div class="next" style="text-align: right; float: right;"><a href="ziparchive.setexternalattributesindex.html">ZipArchive::setExternalAttributesIndex</a></div> <div class="up"><a href="class.ziparchive.html">ZipArchive</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>