Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 1038

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>fileperms</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Filesystem 文件系统函数"
HREF="ref.filesystem.html"><LINK
REL="PREVIOUS"
TITLE="fileowner"
HREF="function.fileowner.html"><LINK
REL="NEXT"
TITLE="filesize"
HREF="function.filesize.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.fileowner.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.filesize.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.fileperms"
></A
>fileperms</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN53088"
></A
><P
>    (PHP 3, PHP 4, PHP 5)</P
>fileperms&nbsp;--&nbsp;取得文件的权限</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN53091"
></A
><H2
>说明</H2
>int <B
CLASS="methodname"
>fileperms</B
> ( string filename )<BR
></BR
><P
>&#13;   返回文件的访问权限,如果出错则返回 <TT
CLASS="constant"
><B
>FALSE</B
></TT
>。
  </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>本函数的结果会被缓存。更多信息参见
<A
HREF="function.clearstatcache.html"
><B
CLASS="function"
>clearstatcache()</B
></A
>。</P
></BLOCKQUOTE
></DIV
><DIV
CLASS="tip"
><BLOCKQUOTE
CLASS="tip"
><P
><B
>提示: </B
>自 <TT
CLASS="literal"
>PHP 5.0.0</TT
>
起本函数也可被<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>某些</I
></SPAN
> URL wrapper 使用。参考<A
HREF="wrappers.html"
>附录 N</A
> 来看哪些 wrapper 支持
<A
HREF="function.stat.html"
><B
CLASS="function"
>stat()</B
></A
> 系列函数的功能。</P
></BLOCKQUOTE
></DIV
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN53110"
></A
><P
><B
>例 1. 以八进制的形式显示文件的权限</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">echo </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">sprintf</font><font color="#007700">(</font><font color="#DD0000">'%o'</font><font color="#007700">, </font><font color="#0000BB">fileperms</font><font color="#007700">(</font><font color="#DD0000">'/tmp'</font><font color="#007700">)), -</font><font color="#0000BB">4</font><font color="#007700">);<br />echo </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">sprintf</font><font color="#007700">(</font><font color="#DD0000">'%o'</font><font color="#007700">, </font><font color="#0000BB">fileperms</font><font color="#007700">(</font><font color="#DD0000">'/etc/passwd'</font><font color="#007700">)), -</font><font color="#0000BB">4</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例的输出类似于:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>1777
0644</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN53115"
></A
><P
><B
>例 2. 输出全部权限</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$perms </font><font color="#007700">= </font><font color="#0000BB">fileperms</font><font color="#007700">(</font><font color="#DD0000">'/etc/passwd'</font><font color="#007700">);<br /><br />if ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0xC000</font><font color="#007700">) == </font><font color="#0000BB">0xC000</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Socket<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'s'</font><font color="#007700">;<br />} elseif ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0xA000</font><font color="#007700">) == </font><font color="#0000BB">0xA000</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Symbolic Link<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'l'</font><font color="#007700">;<br />} elseif ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x8000</font><font color="#007700">) == </font><font color="#0000BB">0x8000</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Regular<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'-'</font><font color="#007700">;<br />} elseif ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x6000</font><font color="#007700">) == </font><font color="#0000BB">0x6000</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Block special<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'b'</font><font color="#007700">;<br />} elseif ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x4000</font><font color="#007700">) == </font><font color="#0000BB">0x4000</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Directory<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'d'</font><font color="#007700">;<br />} elseif ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x2000</font><font color="#007700">) == </font><font color="#0000BB">0x2000</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Character special<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'c'</font><font color="#007700">;<br />} elseif ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x1000</font><font color="#007700">) == </font><font color="#0000BB">0x1000</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// FIFO pipe<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'p'</font><font color="#007700">;<br />} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Unknown<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$info </font><font color="#007700">= </font><font color="#DD0000">'u'</font><font color="#007700">;<br />}<br /><br /></font><font color="#FF8000">// Owner<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0100</font><font color="#007700">) ? </font><font color="#DD0000">'r' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">);<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0080</font><font color="#007700">) ? </font><font color="#DD0000">'w' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">);<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0040</font><font color="#007700">) ?<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0800</font><font color="#007700">) ? </font><font color="#DD0000">'s' </font><font color="#007700">: </font><font color="#DD0000">'x' </font><font color="#007700">) :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0800</font><font color="#007700">) ? </font><font color="#DD0000">'S' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">));<br /><br /></font><font color="#FF8000">// Group<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0020</font><font color="#007700">) ? </font><font color="#DD0000">'r' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">);<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0010</font><font color="#007700">) ? </font><font color="#DD0000">'w' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">);<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0008</font><font color="#007700">) ?<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0400</font><font color="#007700">) ? </font><font color="#DD0000">'s' </font><font color="#007700">: </font><font color="#DD0000">'x' </font><font color="#007700">) :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0400</font><font color="#007700">) ? </font><font color="#DD0000">'S' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">));<br /><br /></font><font color="#FF8000">// World<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0004</font><font color="#007700">) ? </font><font color="#DD0000">'r' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">);<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0002</font><font color="#007700">) ? </font><font color="#DD0000">'w' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">);<br /></font><font color="#0000BB">$info </font><font color="#007700">.= ((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0001</font><font color="#007700">) ?<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0200</font><font color="#007700">) ? </font><font color="#DD0000">'t' </font><font color="#007700">: </font><font color="#DD0000">'x' </font><font color="#007700">) :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</font><font color="#0000BB">$perms </font><font color="#007700">&amp; </font><font color="#0000BB">0x0200</font><font color="#007700">) ? </font><font color="#DD0000">'T' </font><font color="#007700">: </font><font color="#DD0000">'-'</font><font color="#007700">));<br /><br />echo </font><font color="#0000BB">$info</font><font color="#007700">;<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例的输出类似于:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>-rw-r--r--</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;   参见 <A
HREF="function.is-readable.html"
><B
CLASS="function"
>is_readable()</B
></A
> 和 <A
HREF="function.stat.html"
><B
CLASS="function"
>stat()</B
></A
>。
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.fileowner.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.filesize.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>fileowner</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.filesystem.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>filesize</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>