php - 如何仅使用扩展名(*.pdf)检查文件是否存在于 php 中

标签 php file-exists

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

我使用了上面的代码,但它检查了 *.pdf 文件,但没有检查所有属于 .pdf 扩展名的文件

最佳答案

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

关于php - 如何仅使用扩展名(*.pdf)检查文件是否存在于 php 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16813961/

相关文章:

php - Symfony2生产环境: Mapping exception due to custom User class not found in chain configuration

php - 无法使用 PHP 和 PDO 插入

php - 奇怪而烦人的错误 : Call to undefined function mysql_query()

powershell 如果文件不存在日志字符串到文件

c# - 如何验证文件夹是否已存在

php插入日期和日期+1变量

php - PHP登录文件不起作用。继续返回登录页面而不是用户个人资料

batch-file - BATCH 文件中多个文件名的条件 IF EXIST 语句

Linux 机器上存在 PHP file_exists 和特殊字符,如 Å Ø Æ

java - 检查文件是否存在? file.exists() 总是返回 false