<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >opendir</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Directory Functions" HREF="ref.dir.html"><LINK REL="PREVIOUS" TITLE="getcwd" HREF="function.getcwd.html"><LINK REL="NEXT" TITLE="readdir" HREF="function.readdir.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></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" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.getcwd.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.readdir.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.opendir" ></A >opendir</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN20953" ></A ><P > (PHP 3, PHP 4 , PHP 5)</P >opendir -- open directory handle</DIV ><DIV CLASS="refsect1" ><A NAME="AEN20956" ></A ><H2 >Description</H2 >resource <B CLASS="methodname" >opendir</B > ( string path)<BR ></BR ><P > Returns a directory handle to be used in subsequent <A HREF="function.closedir.html" ><B CLASS="function" >closedir()</B ></A >, <A HREF="function.readdir.html" ><B CLASS="function" >readdir()</B ></A >, and <A HREF="function.rewinddir.html" ><B CLASS="function" >rewinddir()</B ></A > calls. </P ><P > If <VAR CLASS="parameter" >path</VAR > is not a valid directory or the directory can not be opened due to permission restrictions or filesystem errors, <B CLASS="function" >opendir()</B > returns <TT CLASS="constant" ><B >FALSE</B ></TT > and generates a PHP error of level <A HREF="missing-stuff.html#errorfunc.constants" > E_WARNING</A >. You can suppress the error output of <B CLASS="function" >opendir()</B > by prepending '<A HREF="language.operators.errorcontrol.html" >@</A >' to the front of the function name. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN20976" ></A ><P ><B >Exemplu 1. <B CLASS="function" >opendir()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$dir </font><font color="#007700">= </font><font color="#DD0000">"/tmp/"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Open a known directory, and proceed to read its contents<br /></font><font color="#007700">if (</font><font color="#0000BB">is_dir</font><font color="#007700">(</font><font color="#0000BB">$dir</font><font color="#007700">)) {<br /> if (</font><font color="#0000BB">$dh </font><font color="#007700">= </font><font color="#0000BB">opendir</font><font color="#007700">(</font><font color="#0000BB">$dir</font><font color="#007700">)) {<br /> while ((</font><font color="#0000BB">$file </font><font color="#007700">= </font><font color="#0000BB">readdir</font><font color="#007700">(</font><font color="#0000BB">$dh</font><font color="#007700">)) !== </font><font color="#0000BB">false</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"filename: $file : filetype: " </font><font color="#007700">. </font><font color="#0000BB">filetype</font><font color="#007700">(</font><font color="#0000BB">$dir </font><font color="#007700">. </font><font color="#0000BB">$file</font><font color="#007700">) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /> }<br /> </font><font color="#0000BB">closedir</font><font color="#007700">(</font><font color="#0000BB">$dh</font><font color="#007700">);<br /> }<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > As of <VAR CLASS="literal" >PHP 4.3.0</VAR > <VAR CLASS="parameter" >path</VAR > can also be any URL which supports directory listing, however only the <VAR CLASS="literal" >file://</VAR > URL wrapper supports this in <VAR CLASS="literal" >PHP 4.3</VAR >. As of <VAR CLASS="literal" >PHP 5.0.0</VAR >, support for the <VAR CLASS="literal" >ftp://</VAR > URL wrapper is included as well. </P ><P > See also <A HREF="function.is-dir.html" ><B CLASS="function" >is_dir()</B ></A >, <A HREF="function.readdir.html" ><B CLASS="function" >readdir()</B ></A >, and <A HREF="class.dir.html" >Dir</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.getcwd.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.readdir.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >getcwd</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.dir.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >readdir</TD ></TR ></TABLE ></DIV ></BODY ></HTML >