How to check file exists in php using only extension like (* .pdf)

$filename = '/www/test1/*.pdf'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } 

I used the code above, but it checks the * .pdf file, but not for all files belonging to the .pdf extension

+4
source share
1 answer
 $filename = '/www/test1/*.pdf'; if (count(glob($filename)) > 0) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } 
+8
source

Source: https://habr.com/ru/post/1483354/


All Articles