php 检测文件是否存在

<?php
/**
 * 文件工具类
 */

namespace Common\Util;
class FileUtil extends CommonUtil
{
    /**
     * @param $file
     * @return bool
     */
    public static function check_file_exists($file)
    {
        if (stripos($file, 'http') === 0) {// 远程文件
            $header = get_headers($file, true);
            return isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'));
        } else {// 本地文件
            return file_exists($file);
        }
    }

}
posted @ 2021-07-05 14:34  TBHacker  阅读(97)  评论(0编辑  收藏  举报