Home Backend Development PHP Tutorial PHP判断文件是否存在、是否可读、目录是否存在的代码_PHP

PHP判断文件是否存在、是否可读、目录是否存在的代码_PHP

Jun 01, 2016 pm 12:08 PM
Does the file exist?

1、案例:
复制代码 代码如下:
$file = 'bitsCN.com.php';
if (is_readable($file) == false) {
die('文件不存在或者无法读取');
} else {
echo '存在';
}
?>

is_readable() 函数判断指定文件名是否可读.
指定的文件或目录存在并且可读,则返回 TRUE

2、案例:
复制代码 代码如下:
$filename = 'bitsCN.com.php';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>

file_exists -- 检查文件或目录是否存在
说明
bool file_exists ( string filename )
如果由 filename 指定的文件或目录存在则返回 TRUE,否则返回 FALSE.

3、案例:
复制代码 代码如下:
$file = 'bitsCN.com.php';
if (is_file($file) == false) {
die('文件不存在或者无法读取');
} else {
echo '存在';
}
?>

is_file -- 判断给定文件名是否为一个正常的文件
说明
bool is_file ( string filename)
如果文件存在且为正常的文件则返回 TRUE.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles