<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >posix_access</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="POSIX Functions" HREF="ref.posix.html"><LINK REL="PREVIOUS" TITLE="POSIX Functions" HREF="ref.posix.html"><LINK REL="NEXT" TITLE="posix_ctermid" HREF="function.posix-ctermid.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="ref.posix.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.posix-ctermid.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.posix-access" ></A >posix_access</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN182772" ></A ><P > (PHP 5 >= 5.1.0RC1)</P >posix_access -- Determine accessibility of a file </DIV ><DIV CLASS="refsect1" ><A NAME="AEN182775" ></A ><H2 >说明</H2 >bool <B CLASS="methodname" >posix_access</B > ( string file [, int mode] )<BR ></BR ><P > <B CLASS="function" >posix_access()</B > checks the user's permission of a file. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN182788" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >file</CODE ></DT ><DD ><P > The name of the file to be tested. </P ></DD ><DT ><CODE CLASS="parameter" >mode</CODE ></DT ><DD ><P > A mask consisting of one or more of <TT CLASS="constant" ><B >POSIX_F_OK</B ></TT >, <TT CLASS="constant" ><B >POSIX_R_OK</B ></TT >, <TT CLASS="constant" ><B >POSIX_W_OK</B ></TT > and <TT CLASS="constant" ><B >POSIX_X_OK</B ></TT >. Defaults to <TT CLASS="constant" ><B >POSIX_F_OK</B ></TT >. </P ><P > <TT CLASS="constant" ><B >POSIX_R_OK</B ></TT >, <TT CLASS="constant" ><B >POSIX_W_OK</B ></TT > and <TT CLASS="constant" ><B >POSIX_X_OK</B ></TT > request checking whether the file exists and has read, write and execute permissions, respectively. <TT CLASS="constant" ><B >POSIX_F_OK</B ></TT > just requests checking for the existence of the file. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN182812" ></A ><H2 >返回值</H2 ><P > 如果成功则返回 <TT CLASS="constant" ><B >TRUE</B ></TT >,失败则返回 <TT CLASS="constant" ><B >FALSE</B ></TT >。 </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN182817" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN182820" ></A ><P ><B >例 1. <B CLASS="function" >posix_access()</B > example</B ></P ><P > This example will check if the $file is readable and writable, otherwise will print an error message. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$file </font><font color="#007700">= </font><font color="#DD0000">'some_file'</font><font color="#007700">;<br /><br />if (</font><font color="#0000BB">posix_access</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">, </font><font color="#0000BB">POSIX_R_OK </font><font color="#007700">| </font><font color="#0000BB">POSIX_W_OK</font><font color="#007700">)) {<br /> echo </font><font color="#DD0000">'The file is readable and writable!'</font><font color="#007700">;<br /><br />} else {<br /> </font><font color="#0000BB">$error </font><font color="#007700">= </font><font color="#0000BB">posix_get_last_error</font><font color="#007700">();<br /><br /> echo </font><font color="#DD0000">"Error $error: " </font><font color="#007700">. </font><font color="#0000BB">posix_strerror</font><font color="#007700">(</font><font color="#0000BB">$error</font><font color="#007700">);<br />}<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN182825" ></A ><H2 >注释</H2 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B >当<A HREF="features.safe-mode.html" >安全模式</A >被激活时,PHP 将检查被操作的文件或者目录是否与正在执行的脚本有相同的 UID(所有者)。</P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN182830" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.posix-get-last-error.html" ><B CLASS="function" >posix_get_last_error()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.posix-strerror.html" ><B CLASS="function" >posix_strerror()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </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="ref.posix.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.posix-ctermid.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >POSIX Functions</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.posix.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >posix_ctermid</TD ></TR ></TABLE ></DIV ></BODY ></HTML >