php check file exists – How to Check If a File Exists in PHP?

0
()

php check file exists – Use the file_exists() Function to Check if File Exists in PHP. The file_exists() function is used to check whether the file or directory exists or not.

php check file exists

Verify if a File exists with PHP. In PHP, function to check if a file exists in a folder path is file_exists.

PHP file_exists() Function

<?php
echo file_exists("welcome.txt");
?>

Check if a file exists using the file_exists() function

Example

<?php

$pathtofile = 'documentation.txt';

if (file_exists($pathtofile)) {
	echo 'The file ' . $pathtofile . ' exists';
} else {
	echo 'The file ' . $pathtofile . ' does not exist';
}

Check if a file exists and readable

index.php

<?php

$pathtofile = 'documentation.txt';

if (is_readable($pathtofile)) {
	echo 'The file ' . $pathtofile . ' exists and is readable';
} else {
	echo 'The file ' . $pathtofile . ' may not exist or unreadable';
}

Free Live Chat for Any Issue

Don’t Miss : PHP File_exists() Function

Read Also:  CSS Create Middle Border Line After Text Example

Check if a file exists and writable

index.php

<?php

$pathtofile = 'documentation.txt';

if (is_writable($pathtofile)) {
	echo sprintf('Good Luck, file %s exists as well as writable', $pathtofile);
} else {
	echo sprintf('sorry, file %s does not exist or is not writable', $pathtofile);
}

Checking whether a file exists

example.php

<?php
    if (file_exists("documentation.png")) {
        print "documentation.png exists!\n";
    } else {
        print "documentation.png does not exist!\n";
    }
?>

How to check if File Exists in PHP?

Verify if a File exists with PHP

Read Also:  Google Style Text Avatar using PHP Example

index.php

$pathtofile = '/pakainfo_v1/mdeia/pakainfo_v1.ext';

echo file_exists($pathtofile);

if (file_exists($pathtofile)) {
   echo "Good Luck, File found in directory path";} 
else {
   echo "sorry, File not found in the path";}

Download

I hope you get an idea about php check file exists.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

How useful was this post?

Click on a star to rate it!