Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What type of Data is in Blob?
Message
De
06/11/2007 04:24:53
 
 
À
05/11/2007 19:19:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01233743
Message ID:
01266903
Vues:
21
>The contents of DOC, XLS and VSD... and maybe others... have the same code in your function when you check the filetype [left(filetostr(cFile),5)=...]. Then how to know it's really a DOC?

It look like the header is not unique for these files, so you must look for some other unique data. Try this
Function filetype
  Lparameters lcData
  Local lcReturn,lcContents, lcXLSTextToSearchFor, lcVSDTextToSearchFor
  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
    lcXLSTextToSearchFor=Chr(0x05)+Chr(0x00)+Chr(0x44)+Chr(0x00)+Chr(0x6F)+Chr(0x00)+Chr(0x63)+Chr(0x00);
       +Chr(0x75)+Chr(0x00)+Chr(0x6D)+Chr(0x00)+Chr(0x65)+Chr(0x00)+Chr(0x6E)+Chr(0x00);
       +Chr(0x74)+Chr(0x00)+Chr(0x53)+Chr(0x00)+Chr(0x75)+Chr(0x00)+Chr(0x6D)+Chr(0x00)
    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 lcXLSTextToSearchFor$lcContents
        lcReturn='XLS'
      Case 'MSWordDoc+chr(0)+Chr(0x10)$lcContents
        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
I don't have any VSD files to inspect, but it should be relatively easy to find some unique data in these files also, and search for them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform