I need to check if a file is on HDD at a specified location ($path.$file_name).
Which is the difference between is_file() and file_exists() functions and which is better/faster to use in PHP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
is_file()will returnfalseif the given path points to a directory.file_exists()will returntrueif 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, useis_file(). Otherwise, usefile_exists().