文件相关处理

  常用的一些对于文件相关处理

  

一. 判断文件是否存在

// 验证文件是否存在
function existFile($file)
{
    if( empty($file) ) return false;

    if(stripos($file,'http') === 0){
        // 远程图片
        $header = get_headers($file,1);
        return isset($header[0]) && (strpos($header[0],'200') || strpos($header[0],'304')) && stripos($header[0],'OK');
    }else{
        // 验证是否有中文
        if(preg_match("/([\x81-\xfe][\x40-\xfe])/", $file, $match)){
            $file = iconv('UTF-8', 'GBK', $file);
        }
        return file_exists($file);
    }
}

  注: 匹配字符串全部是中文 

preg_match_all("/^([\x81-\xfe][\x40-\xfe])+$/", $str, $match)

  

 

posted @ 2018-08-27 15:56  X-Wolf  阅读(243)  评论(0编辑  收藏  举报