How to determine whether the path is a folder or a file in php
In PHP, you can use the if statement and the is_dir() and is_file() functions to determine whether the path is a folder or a file. The syntax "if(is_dir($file)){echo "is a folder"; }else if(is_file($file)){echo "is a file"}".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php determines whether the path is a folder or File
In PHP, you can use the if statement and the is_dir() and is_file() functions to determine whether the path is a folder or a file.
The is_dir() function can check whether the specified file is a directory. If the directory exists, this function returns TRUE.
The is_file() function can check whether the specified file is a regular file. If the file is a regular file, this function returns TRUE.
Implementation code:
<?php header("Content-type:text/html;charset=utf-8"); $file = "img/1.jpg"; if (is_dir($file)) { echo "指定路径是文件夹"; } else if (is_file($file)) { echo "指定路径是文件"; } else { echo "指定路径不是常规文件 "; } ?>
Output result:
If $f# If the value of ##ile is changed to "img", it will output:
PHP Video Tutorial"
The above is the detailed content of How to determine whether the path is a folder or a file in php. For more information, please follow other related articles on the PHP Chinese website!

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

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

Hot Article

Hot Tools

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

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

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools
