Yes there are some differences:
file_exists() checks whether the directory or file exists, passed as argument.
is_file() The definition of the manual is
Tells whether the Given file is a regular file.
Informs if the file/string passed as argument is a file regular
According to that answer from Soen, some examples of unregulated files are:
Basically what the function does is to check the string($filename
) is valid or does not contain characters strangers positive case checks whether $filename
represents a file, otherwise returns false
.
I did 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
Upshot:
X |Pasta |Arquivo|Device|Pasta ou arquivo com caracter estranho
is_file |false |true |false |false
file_exists |true |true |true |false
is_file
I think it’s to make sure it’s not a directory... just see the manual http://php.net/manual/en/function.is-file.php– Franchesco
To see if it’s not directory I just use
!is_dir($file)
– Wallace Maxters
Puts, many answers equal! cascade effect
– Wallace Maxters