Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check file exist 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 above code but it checks for *.pdf file but not for all files belongs to .pdf extension

like image 252
M Gaidhane Avatar asked Dec 26 '22 03:12

M Gaidhane


1 Answers

$filename = '/www/test1/*.pdf';
if (count(glob($filename)) > 0) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
like image 113
Mark Baker Avatar answered Mar 03 '23 10:03

Mark Baker