Lost My Pieces Piano Version

download Lost My Pieces Piano Version

of 4

Transcript of Lost My Pieces Piano Version

  • 7/21/2019 Lost My Pieces Piano Version

    1/4

    Programming

  • 7/21/2019 Lost My Pieces Piano Version

    2/4

    ther method is con!erting your DB$* lass to C# to detect mimetypes$ *hey &ill "e identi4ed "y a mi5 of sniEng the 4rst /F2 Bytes of a 4leand a set of Gno&n types$

    5ample (not all 4les types are listed here):

    .. checG &hether or not the uploaded 4le is an image:!ar content*ype 'ime*ypes$6etContent*ype(?ile7ploadH$Posted?ile$?ileame)8if(content*ype$,tarts@ith(image))9 .. do something &ith the image $$$ereIs the class:using ,ystem8using ,ystem$Collections$6eneric8

    using ,ystem$LinJ8using ,ystem$Kuntime$%nterop,er!ices8using ,ystem$%8

    pu"lic class 'ime*ypes9 pri!ate static Listictionaryll%mport(urlmon$dll Char,et Char,et$Auto)N

    pri!ate static e5tern 7%nt3/ ?ind'ime?rom>ata( 7%nt3/ pBC M'arshalAs(7nmanaged*ype$LP,tr)N string p&O7rl M'arshalAs(7nmanaged*ype$LPArray)N "yteMN pBuer 7%nt3/ c",iOe M'arshalAs(7nmanaged*ype$LP,tr)N string p&O'imeProposed 7%nt3/ d&'ime?lags ref 7%nt3/pp&O'imeut 7%nt3/ d&Keser!erd )8 pu"lic static string 6etContent*ype(string 4leame) 9 if (Gno&n*ypes null QQ mime*ypes null) %nitialiOe'ime*ypeLists()8

    string content*ype 8 string e5tension ,ystem$%$Path$6et5tension(4leame)$Keplace($)$*oLo&er()8 mime*ypes$*ry6etDalue(e5tension out content*ype)8 if (string$%sullrmpty(content*ype) QQGno&n*ypes$Contains(content*ype)) 9 string header*ype ,can?ile?or'ime*ype(4leame)8

  • 7/21/2019 Lost My Pieces Piano Version

    3/4

    if (header*ype application.octet-stream QQstring$%sullrmpty(content*ype)) content*ype header*ype8 return content*ype8

    pri!ate static string ,can?ile?or'ime*ype(string 4leame) 9 try 9 "yteMN "uer ne& "yteM/F2N8 using (?ile,tream fs ne& ?ile,tream(4leame ?ile'ode$pen)) 9 int readLength Con!ert$*o%nt3/('ath$'in(/F2 fs$Length))8 fs$Kead("uer 1 readLength)8

    7%nt3/ mime*ype default(7%nt3/)8 ?ind'ime?rom>ata(1 null "uer /F2 null 1 ref mime*ype 1)8 %ntPtr mime*ypePtr ne& %ntPtr(mime*ype)8 string mime 'arshal$Ptr*o,tring7ni(mime*ypePtr)8 'arshal$?reeCo*asG'em(mime*ypePtr)8 if (string$%sullrmpty(mime)) mime application.octet-stream8 return mime8 catch (5ception e5)

    9 return application.octet-stream8

    pri!ate static !oid %nitialiOe'ime*ypeLists() 9 Gno&n*ypes ne& stringMN 9 te5t.insert 4le type$*oList()8

    mime*ypes ne& >ictionary

  • 7/21/2019 Lost My Pieces Piano Version

    4/4

    checG if an e5tension is t5t "ut the mime-type is "inary data "ecause thatmeans that this 4le is not &hat it pretends to "e$