Finding+the+MIME+type+of+a+file

//by Jon Ripley, May 2007//

To read the MIME type of a file call passing it a file extension, for example: code format="bb4w" PRINT "The MIME type of a .html file is ";FN_GetMIMEType("html") code

The code for is: code format="bb4w" 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% code 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.