User Tools

Site Tools


finding_20the_20mime_20type_20of_20a_20file

Finding the MIME type of a file

by Jon Ripley, May 2007

To read the MIME type of a file call “FN_GetMIMEType” passing it a file extension, for example:

        PRINT "The MIME type of a .html file is ";FN_GetMIMEType("html")


The code for “FN_GetMIMEType” is:

        DEF FN_GetMIMEType(T$)
        LOCAL B%, H%, L%, R%, T%
        L% = 255 : DIM B% LOCAL L%
        SYS "RegOpenKeyEx", &80000000, "."+T$, 0, &20001, ^H% TO R%
        IF R% = 0 THEN
          SYS "RegQueryValueEx", H%, "Content Type", 0, ^T%, B%, ^L% TO R%
          REM Uncomment the next line to set a default MIME type if none is found
          REM IF R% $$B% = MIMEDefault$
          SYS "RegCloseKey", H%
        ENDIF
        = $$B%

“FN_GetMIMEType” returns an empty string if no MIME type is found in the registry for the requested file extension. To set a default MIME type for all unknown extensions uncomment the specified line and replace MIMEDefault$ with your fail safe type.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
finding_20the_20mime_20type_20of_20a_20file.txt · Last modified: 2018/04/17 17:12 by tbest3112