How to Check File is Exists or Not in PHP?
Hi Developer,
In this quick guide, we will teach you how to check if a file exists in PHP. We will provide an example of checking if a file with a URL image exists using PHP. You will learn how to check if an image exists in PHP. Please follow the tutorial steps below to learn how to check if a file exists in PHP.
To check whether a file exists in PHP, you can use the file_exists() function. This function takes a file path as its parameter and returns a boolean value of true if the file exists and false otherwise. Here's an example:
index.php
<?php
$filePath = 'path/to/file.txt';
if (file_exists($filePath)) {
echo 'File exists';
} else {
echo 'File does not exist';
}
?>
In this example, the file_exists() function is used to check whether a file with the path path/to/file.txt exists or not. If the file exists, the message "File exists" is printed to the screen. Otherwise, the message "File does not exist" is printed.
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Google Recaptcha V2 Example Tutorial
- JQuery Ajax CRUD Operations in PHP MySQL Example
- How to Get Filename from Path in PHP?
- MySQL Query to Get Current Year Data Example
- How to Get File Name without Extension in PHP?
- How to Remove White Space from String in PHP?
- How to Check If String is URL or Not in PHP?
- How to Convert Array Key to Lowercase in PHP?
- How to Convert Object into Array in PHP?
- How to Get Minimum Key Value of Array in PHP?
- How to access PHP variables in JQuery?
- How to Count Number of Files in a Directory in PHP?
- How to Find Day Name from Specific Date in PHP?
- How to use Google Maps API with JQuery PHP?