php 检测文件是否存在

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

namespace CommonUtil;
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);
        }
    }

}
原文地址:https://www.cnblogs.com/jiqing9006/p/14972272.html