zoukankan      html  css  js  c++  java
  • php 获取文件后缀

      /**
         * 获取文件后缀
       * $path 本地存储临时文件路径 *
    */ private function getFileType($path){ $fp=fopen($path,'r'); $bin = fread($fp, 2); //只读2字节 fclose($fp); $str_info = @unpack('C2chars', $bin);//Unpack data from binary string $type_code = intval($str_info['chars1'].$str_info['chars2']);// Get the integer value of a variable $file_type =''; switch ($type_code) { case 7790: $file_type = 'exe'; break; case 7784: $file_type = 'midi'; break; case 8075: $file_type = 'zip'; break; case 8297: $file_type = 'rar'; break; case 255216: $file_type = 'jpg'; break; case 7173: $file_type = 'gif'; break; case 6677: $file_type = 'bmp'; break; case 13780: $file_type = 'png'; break; default: $file_type = 'unknown'; break; } return $file_type; }
  • 相关阅读:
    C# 数据库连接字符串拼接
    C# 线程同步计数存在的问题
    字符串操作
    字符串位置
    6个基本函数
    占位符
    str转换成int
    python运算符6
    python运算符5
    python运算符4
  • 原文地址:https://www.cnblogs.com/-mrl/p/7815793.html
Copyright © 2011-2022 走看看