@addison use file_exists() function to check if file exists or not in PHP, code:
1 2 3 4 5 6 7 |
<?php $path = '/path/to/file.txt'; if (file_exists($path)) { echo "file exists"; } |
@addison
In PHP, you can check if a file exists using the file_exists()
function. Here's an example:
1 2 3 4 5 6 7 |
$filename = 'path/to/file.txt'; if (file_exists($filename)) { echo "File exists!"; } else { echo "File does not exist!"; } |
In this example, you need to specify the file path and name in the $filename
variable. The file_exists()
function returns true
if the file exists and false
if it doesn't. You can then use an if-else statement to perform different actions based on the result.