PHP中的is_file或file_exists [英] is_file or file_exists in PHP
问题描述
我需要检查文件是否在指定位置($ path.$ file_name)的HDD上.
I need to check if a file is on HDD at a specified location ($path.$file_name).
is_file()
和file_exists()
函数,在PHP中使用哪种更好/更快?
Which is the difference between is_file()
and file_exists()
functions and which is better/faster to use in PHP?
推荐答案
is_file()
将返回false
.如果给定路径指向有效文件或目录,则file_exists()
将返回true
.因此,这完全取决于您的需求.如果您想专门了解 是否为文件,请使用is_file()
.否则,请使用file_exists()
.
is_file()
will return false
if the given path points to a directory. file_exists()
will return true
if the given path points to a valid file or directory. So it would depend entirely on your needs. If you want to know specifically if it's a file or not, use is_file()
. Otherwise, use file_exists()
.
这篇关于PHP中的is_file或file_exists的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!