c#多图片上传并生成缩略图的实例代码(2)

#region 验证上传文件的格式
     /// <summary>
     /// 验证上传文件是否是图片
     /// </summary>
     /// <param>文件的保存路径</param>
     /// <returns></returns>
     private bool IsImg(string FilePath)
     {
         using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
         {
             bool result = false;
             BinaryReader br = new BinaryReader(fs, System.Text.Encoding.UTF8);
             string strImg = "";
             byte buffer;
             try
             {
                 buffer = br.ReadByte();
                 strImg = buffer.ToString();
                 buffer = br.ReadByte();
                 strImg += buffer.ToString();
             }
             catch
             {
                 fs.Close();
                 br.Close();

             }
             if (strImg == "255216" || strImg == "13780")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
             {
                 result = true;
             }
             return result;
         }
     }
     #endregion

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgsgw.html