Php Flow » Php

How to Check file or Directory exist in PHP

This tutorial is about check file or directory is exist or not on server.PHP has file_exists($path) function to check
File is exist or not.
Today I am working on XML file. Where I will convert XML file into Associative array.
So first I need to assured file is exist or not if exist then I will do next step otherwise I will show message file does not exist.
This method also work on directory to check directory EXIST or NOT.This method return true if exist otherwise false.

1
2
3
4
5
6
7
8
9
if (file_exists($path)) {
    echo "The file $path exists";
} else {
    echo "The file $path does not exist";
}
Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook.

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>