📄 pharfileinfo.setmetadata.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Sets file-specific meta-data saved with a file</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pharfileinfo.setcompressedgz.html">PharFileInfo::setCompressedGZ</a></div> <div class="next" style="text-align: right; float: right;"><a href="pharfileinfo.setuncompressed.html">PharFileInfo::setUncompressed</a></div> <div class="up"><a href="class.PharFileInfo.html">PharFileInfo</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="pharfileinfo.setmetadata" class="refentry"> <div class="refnamediv"> <h1 class="refname">PharFileInfo::setMetaData</h1> <p class="verinfo">(PECL phar:1.0.0-1.2.1)</p><p class="refpurpose"><span class="refname">PharFileInfo::setMetaData</span> — <span class="dc-title">Sets file-specific meta-data saved with a file</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><b>PharFileInfo::setMetaData</b></b></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$metadata</tt></span> )</div> <p class="para rdfs-comment"> <b>setMetaData()</b> should only be used to store customized data in a file that cannot be represented with existing information stored with a file. Meta-data can significantly slow down the performance of loading a phar archive if the data is large, or if there are many files containing meta-data. It is important to note that file permissions are natively supported inside a phar; it is possible to set them with the <a href="pharfileinfo.chmod.html" class="function">PharFileInfo::chmod()</a> method. As with all functionality that modifies the contents of a phar, the <a href="phar.configuration.html#ini.phar.readonly" class="link">phar.readonly</a> INI variable must be off in order to succeed if the file is within a <a href="class.Phar.html" class="classname">Phar</a> archive. Files within <a href="class.PharData.html" class="classname">PharData</a> archives do not have this restriction. </p> <p class="para"> Some possible uses for meta-data include passing a user/group that should be set when a file is extracted from the phar to disk. Other uses could include explicitly specifying a MIME type to return. However, any useful data that describes a file, but should not be contained inside of it may be stored. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">metadata</tt></i></span> <dd> <p class="para"> Any PHP variable containing information to store alongside a file </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 A <b>PharFileInfo::setMetaData()</b> example</b></p> <div class="example-contents"><p> </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// make sure it doesn't exist<br /></span><span style="color: #007700">@</span><span style="color: #0000BB">unlink</span><span style="color: #007700">(</span><span style="color: #DD0000">'brandnewphar.phar'</span><span style="color: #007700">);<br />try {<br /> </span><span style="color: #0000BB">$p </span><span style="color: #007700">= new </span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">) . </span><span style="color: #DD0000">'/brandnewphar.phar'</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #DD0000">'brandnewphar.phar'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$p</span><span style="color: #007700">[</span><span style="color: #DD0000">'file.txt'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'hello'</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$p</span><span style="color: #007700">[</span><span style="color: #DD0000">'file.txt'</span><span style="color: #007700">]-></span><span style="color: #0000BB">setMetaData</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'user' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'bill'</span><span style="color: #007700">, </span><span style="color: #DD0000">'mime-type' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">));<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$p</span><span style="color: #007700">[</span><span style="color: #DD0000">'file.txt'</span><span style="color: #007700">]-></span><span style="color: #0000BB">getMetaData</span><span style="color: #007700">());<br />} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'Could not create/modify phar: '</span><span style="color: #007700">, </span><span style="color: #0000BB">$e</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>array(2) { ["user"]=> string(4) "bill" ["mime-type"]=> string(10) "text/plain"}</pre></div> </pre></div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="pharfileinfo.hasmetadata.html" class="function" rel="rdfs-seeAlso">PharFileInfo::hasMetadata()</a></li> <li class="member"><a href="pharfileinfo.getmetadata.html" class="function" rel="rdfs-seeAlso">PharFileInfo::getMetadata()</a></li> <li class="member"><a href="pharfileinfo.delmetadata.html" class="function" rel="rdfs-seeAlso">PharFileInfo::delMetadata()</a></li> <li class="member"><a href="phardata.setmetadata.html" class="function" rel="rdfs-seeAlso">Phar::setMetadata()</a></li> <li class="member"><a href="phar.hasmetadata.html" class="function" rel="rdfs-seeAlso">Phar::hasMetadata()</a></li> <li class="member"><a href="phar.getmetadata.html" class="function" rel="rdfs-seeAlso">Phar::getMetadata()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pharfileinfo.setcompressedgz.html">PharFileInfo::setCompressedGZ</a></div> <div class="next" style="text-align: right; float: right;"><a href="pharfileinfo.setuncompressed.html">PharFileInfo::setUncompressed</a></div> <div class="up"><a href="class.PharFileInfo.html">PharFileInfo</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -