pTutorial

New way to learn PHP function

PHP file_exists Function

Syntax

file_exists($string);

Parameter Description
String Any string (file name)

Definition

It returns TRUE if it does exist otherwise return false.

Usage

Checks whether a file or directory with the given name of $string exists or not.

Example of file_exists function

<?php

// file.txt does not exist

var_dump( file_exists('file.txt') );

?>

You can directly pass the file or directory into the file_exist function as shown above. In this case file does not exist so that result will be false.

Example

<form method="post">
Enter the directory or file name <br/>
<input type="text" name="uk">
<input type="submit" name="sub">
</form>



<?php
if(isset($_POST['sub']))
{
	$uk=$_POST['uk'];

if(file_exists($uk))
{
echo "File exist";	

}
else
echo "Not exist";
}

?>


Output

Enter the directory or file name

According to the above example you can check file or directory existence by your choice.

Enter the file or directory name into the text box and press submit button to check.

QUOTES OF THE DAY

Knowledge without integrity is dangerous and dreadful.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER