Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What type of Data is in Blob?
Message
From
03/11/2007 11:21:51
 
 
To
03/11/2007 10:02:54
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01233743
Message ID:
01266396
Views:
35
>And how to know if it's a DOC or PDF file?

Using a hex editor on a few old and new DOC and PDF files, I came up with this modified function. As I wrote earlier, the function is easy to extend.
Function filetype
  Lparameters lcData
  Local lcReturn,lcContents
  If Pcount()=0 Or Vartype(lcData)#'C'
    lcReturn=''
  Else
    If Adir(laDummy,lcData)>0 && File
      lcContents=Filetostr(lcData)
    Else && Memory variabøe
      lcContents=lcData
    Endif
    Do Case
      Case Len(lcContents)<4
        lcReturn=''
      Case Left(lcContents,3)=Chr(0xFF)+Chr(0xD8)+Chr(0xFF)
        lcReturn='JPG'
      Case Left(lcContents,3)='GIF'
        lcReturn='GIF'
      Case Substr(lcContents,42,3)='EMF'
        lcReturn='EMF'
      Case Left(lcContents,4)=Chr(0xD7)+Chr(0xCD)+Chr(0xC6)+Chr(0x9A)
        lcReturn='WMF'
      Case Left(lcContents,4)=Chr(0x4D)+Chr(0x4D)+Chr(0x00)+Chr(0x2A)
        lcReturn='TIF'
      Case Left(lcContents,4)=Chr(0x89)+'PNG'
        lcReturn='PNG'
      Case Left(lcContents,5)=Chr(0xD0)+Chr(0xCF)+Chr(0x11)+Chr(0xE0)+Chr(0xA1)
        lcReturn='DOC'
      Case Left(lcContents,5)='%PDF-'
        lcReturn='PDF'
      Case Left(lcContents,2)='BM'
        lcReturn='BMP'
      Case Left(lcContents,3)='CWS' And Asc(Substr(lcContents,4,1))<16
        lcReturn='SWF'
      Case Left(lcContents,3)='FWS'  And Asc(Substr(lcContents,4,1))<16
        lcReturn='SWF'
      Otherwise
        lcReturn=''
    Endcase
  Endif
Return lcReturn
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform