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;