下面我们一起来看一个利用php检测指定目录中是不是为空目录了,这里方法是遍历目录得出的结果,下面我们来看个例子。
今天在写上传图片作为封面的时候 为了避免重复的上传封面而导致。封面图片乱设置。就百度出了判断文件夹是否为空的代码
代码如下 | 复制代码 |
$dir = opendir('1'); |
获取文件夹1的目录。 因为函数会获取.和.. 本身和上级目录都显示出来。这样就循环成了1这样的结果也就是文件夹为空。如果循环到2的时候就会显示出目录下的文件。
例子
代码如下 | 复制代码 |
function is_empty_dir($dir_path) $dir = opendir($dir_path); $is_empty = true; while ($file = readdir($dir)){ if($file == ‘.’ || $file == ‘..’) continue; $is_empty = false; break; } closedir($dir); return $is_empty; } ?> |
例子
代码如下 | 复制代码 |
$root = dirname(__FILE__); $isempty = file_exit(); //检查目录是否为空 global $path; |

Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool