检测是否是图片代码:
public static bool IsImage(HttpPostedFileBase hpf) { bool result = false; Stream fs = hpf.InputStream; BinaryReader r = new BinaryReader(fs); string fileclass = ""; byte buffer; try { buffer = r.ReadByte(); fileclass = buffer.ToString(); buffer = r.ReadByte(); fileclass += buffer.ToString(); } catch (Exception ex){ } if (fileclass == "255216" || fileclass == "7173" || fileclass == "13780" || fileclass == "6677") { result = true; } else { result = false; } r.Close(); fs.Close(); return result; }
上传代码:
HttpPostedFileBase file = Request.Files["imgFile"]; bool isimage = Common.Upload.IsImage(file);
//为什么到这里后文件的长度就变为了0,从而导致下面上传失败?
string fileurl = Common.Upload.UploadFile(file, type, uploaddir, uploadconfig.custompath, width, height);
为什么运行完Common.Upload.IsImage(file)后,文件的长度就变为了0?
相关问题
- In what practical case bool(std::ifstream) != std:
- Delphi stream panel to file
- Webshot to Google Drive without storing intermedia
- Fail to define an infinite stream
- Detecting file type from buffer in node js?
相关文章
- node.js modify file data stream?
- MemoryStream disables reading when returned
- Convert HttpContent into byte[]
- MemoryStream.WriteTo(Stream destinationStream) ver
- c# saving very large bitmaps as jpegs (or any othe
- Writing a stream protocol: Message size field or M
- How to compose transform Streams in node.js
- Java: Saving StreamResult to a file
在
bool isimage = Common.Upload.IsImage(file);
之后添加file.InputStream.Positon = 0;