예제 #1
0
 /**
  * [checkFileExists 检查文件是否存在 和 判断后缀名是否正确
  * @param  string | array $files 要检查的文件(文件列表)
  * @param  string $ext 是否检查后缀
  * @throws \InvalidArgumentException
  * @throws NotFoundException
  * @return array|string [type]        [description]
  */
 public static function exists($files, $ext = null)
 {
     $ext = $ext ? trim($ext, '. ') : null;
     $files = StrHelper::toArray($files);
     foreach ($files as $file) {
         $file = trim($file);
         if (!file_exists($file)) {
             throw new NotFoundException("文件 {$file} 不存在!");
         }
         // if ( $ext && strrchr($file,'.') != '.'.$ext ) {
         if ($ext && preg_match("/\\.({$ext})\$/i", $file)) {
             throw new \InvalidArgumentException("{$file} 不是 {$ext} 文件!");
         }
     }
     return $files;
 }