check file exists in php – How to Check if Remote File Exists using PHP?

check file exists in php – There are following the best check file exists in php Examples using File_exists, Fopen, Fwrite, Fclose, Fgets, copy, unlink.

check file exists in php

Check if a file exists using the file_exists() function

<?php

$user_fl_name = 'welcome.txt';

if (file_exists($user_fl_name)) {
    $message = "The file $user_fl_name exists";
} else {
    $message = "The file $user_fl_name does not exist";
}
echo $message;

Check if a file exists using the is_file() function

<?php

$user_fl_name = 'welcome.txt';

if (is_file($user_fl_name)) {
    $message = "The file $user_fl_name exists";
} else {
    $message = "The file $user_fl_name does not exist";
}
echo $message;

Don’t Miss : PHP GET_HEADERS

Check if a file exists and readable

<?php

$user_fl_name = 'welcome.txt';

if (is_readable($user_fl_name)) {
    $message = "The file $user_fl_name exists";
} else {
    $message = "The file $user_fl_name does not exist";
}
echo $message;

Check if a file exists and writable

<?php

$user_fl_name = 'welcome.txt';

if (is_writable($user_fl_name)) {
    $message = "The file $user_fl_name exists";
} else {
    $message = "The file $user_fl_name does not exist";
}

echo $message;

See also :  PHP Codeigniter 3 - Basic CRUD Operation with MySQL Database with example

Leave a Reply

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