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.
finding_20the_20mime_20type_20of_20a_20file.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1