Usage examples of opendir function in php
Oct 08, 2016 pm 04:04 PMThis article mainly introduces the usage of the opendir function in php. It details the usage of the opendir function to open a directory and related precautions in the form of examples. It has certain reference value. Friends in need can refer to it
This article analyzes the usage of opendir function in php with examples. Share it with everyone for your reference. The details are as follows:
opendir syntax: opendir(path,context)
Directory, function description: open a directory handle, the opendir() function opens a directory handle, then the function returns a directory stream, otherwise it returns false. Let's look at an example of opendir listing all files in the directory. The code is as follows:
<span style="color: #800080;">$dirs</span> ='./';<span style="color: #008000;">//</span><span style="color: #008000;">指定當(dāng)前上當(dāng) </span> <span style="color: #0000ff;">if</span>( <span style="color: #008080;">is_dir</span>( <span style="color: #800080;">$dirs</span><span style="color: #000000;"> ) ) { </span><span style="color: #800080;">$hanld</span> = <span style="color: #008080;">opendir</span>(<span style="color: #800080;">$dirs</span><span style="color: #000000;">); </span><span style="color: #0000ff;">while</span> ((<span style="color: #800080;">$file</span> = <span style="color: #008080;">readdir</span>(<span style="color: #800080;">$hanld</span>)) !== <span style="color: #0000ff;">false</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">echo</span> "文件名: " . <span style="color: #800080;">$file</span> . "<br />"<span style="color: #000000;">; } </span><span style="color: #008080;">closedir</span>(<span style="color: #800080;">$hanld</span><span style="color: #000000;">); } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">echo</span> '不是目錄'<span style="color: #000000;">; }</span>
Output result:
File name: a
File name: b
File name: www.manongjc.com
Tips and Notes:
Note: Starting from PHP 5.0.0, the path parameter supports ftp:// URL wrapper
Note: In PHP 4.3.0, the path parameter can be any URL that supports directory listing, but in PHP 4 only the file:// URL wrapper supports this feature.
I hope this article will be helpful to everyone’s PHP programming design.
Related reading:
http://www.manongjc.com/article/1495.html
http://www.manongjc.com/article/1496.html

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)