function.chmod.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 161 行

HTML
161
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Changes file mode</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="function.chgrp.html">chgrp</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.chown.html">chown</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.chmod" class="refentry"> <div class="refnamediv">  <h1 class="refname">chmod</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">chmod</span> &mdash; <span class="dc-title">Changes file mode</span></p> </div>  <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">bool</span> <span class="methodname"><b><b>chmod</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$filename</tt></span>   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$mode</tt></span>   )</div>  <p class="para rdfs-comment">   Attempts to change the mode of the specified file to that given in   <i><tt class="parameter">mode</tt></i>.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">filename</tt></i></span>     <dd>      <p class="para">       Path to the file.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">mode</tt></i></span>     <dd>      <p class="para">       Note that <i><tt class="parameter">mode</tt></i> is not automatically       assumed to be an octal value, so strings (such as &quot;g+w&quot;) will       not work properly. To ensure the expected operation,       you need to prefix <i><tt class="parameter">mode</tt></i> with a zero (0):      </p>      <p class="para">       <div class="informalexample">        <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/somedir/somefile"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">755</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;decimal;&nbsp;probably&nbsp;incorrect<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/somedir/somefile"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"u+rwx,go+rx"</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;string;&nbsp;incorrect<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/somedir/somefile"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0755</span><span style="color: #007700">);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;octal;&nbsp;correct&nbsp;value&nbsp;of&nbsp;mode<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>        </div>       </div>      </p>      <p class="para">       The <i><tt class="parameter">mode</tt></i> parameter consists of three octal       number components specifying access restrictions for the owner,       the user group in which the owner is in, and to everybody else in       this order. One component can be computed by adding up the needed       permissions for that target user base. Number 1 means that you       grant execute rights, number 2 means that you make the file       writeable, number 4 means that you make the file readable. Add       up these numbers to specify needed rights. You can also read more       about modes on Unix systems with &#039;man 1 chmod&#039; and &#039;man 2 chmod&#039;.      </p>      <p class="para">       <div class="informalexample">        <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Read&nbsp;and&nbsp;write&nbsp;for&nbsp;owner,&nbsp;nothing&nbsp;for&nbsp;everybody&nbsp;else<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/somedir/somefile"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0600</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Read&nbsp;and&nbsp;write&nbsp;for&nbsp;owner,&nbsp;read&nbsp;for&nbsp;everybody&nbsp;else<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/somedir/somefile"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0644</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Everything&nbsp;for&nbsp;owner,&nbsp;read&nbsp;and&nbsp;execute&nbsp;for&nbsp;others<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/somedir/somefile"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0755</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Everything&nbsp;for&nbsp;owner,&nbsp;read&nbsp;and&nbsp;execute&nbsp;for&nbsp;owner's&nbsp;group<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/somedir/somefile"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0750</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>        </div>       </div>      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure.  </p> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <blockquote><p><b class="note">Note</b>:        The current user is the user under which PHP runs. It is probably not the    same user you use for normal shell or FTP access. The mode can be changed    only by user who owns the file on most systems.   <br />  </p></blockquote>  <blockquote><p><b class="note">Note</b>: <span class="simpara">This function will not work on <a href="features.remote-files.html" class="link">remote files</a> as the file tobe examined must be accessible via the server&#039;s filesystem.</span></p></blockquote>  <blockquote><p><b class="note">Note</b>:        When <a href="features.safe-mode.html#ini.safe-mode" class="link">safe mode</a> is enabled, PHP checks whether the files or directories    you are about to operate on have the same UID (owner) as the script that    is being executed. In addition, you cannot set the SUID, SGID and sticky    bits.   <br />  </p></blockquote> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.chown.html" class="function" rel="rdfs-seeAlso">chown()</a></li>    <li class="member"><a href="function.chgrp.html" class="function" rel="rdfs-seeAlso">chgrp()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.chgrp.html">chgrp</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.chown.html">chown</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?