First you have kno which characters are allowed in a filename. In windows a filename cannot have any of \/*😐?><.
so a sample code will be:
<?php
function chkFileName($filename) {
return (strlen($filename) == strcspn($filename,'\\/*?:<>|'));
}
// remember to escape \ with \\ before passing it to the function.
// cuz a \ at the end of the filename will cause parse errors.
if (chkFileName('valid_filename')) {
echo 'Filename is valid';
} else {
echo 'Filename is not valid';
}
?>