Yes there are some differences:
file_exists () checks whether the directory or file exists as an argument.
is_file () The manual definition is
Tell whether the given file is a regular file.
Informs if the / string passed as argument is a regular file
According to SOen's response , some examples of non-regular files are:
Basically what the function does is check if the specified string ( $filename
) is valid or does not contain strange characters positive case checks if $filename
represents a file, otherwise returns false
.
I made some tests comparing the two functions, the result is table below
Project Structure
Raiz
foo
3.txt - Atalho.lnk
txt
1.txt
abců.txt
ů.txt
ů
<?php
var_dump(is_file('foo')); //pasta
var_dump(is_file('txt/1.txt')); //arquivo
var_dump(is_file('C:\')); //device
var_dump(is_file('txt/abců.txt')); //arquivo com caracter estranho
var_dump(is_file('txt/ů.txt')); //arquivo com caracter estranho
var_dump(is_file('txt/ů')); // pasta com caracter estranho
var_dump(file_exists('foo')); //pasta
var_dump(file_exists('txt/1.txt')); //arquivo
var_dump(file_exists('C:\')); // device
var_dump(file_exists('txt/ů.txt')); //arquivo com caracter estranho
var_dump(file_exists('txt/abců.txt')); //arquivo com caracter estranho
var_dump(file_exists('ů'); //pasta com caracter estranho
Result:
X |Pasta |Arquivo|Device|Pasta ou arquivo com caracter estranho
is_file |false |true |false |false
file_exists |true |true |true |false