fileGetMimeType

Gets the MIME type for the file path/file object you have specified.

fileGetMimeType(file, strict) → returns string

Argument Reference

file any
Required

Name of the file object or full path on disk to the file if strict is set to true. If you do not specify the full path, the file is assumed to be present in the temp directory, as returned by the function getTempDirectory.

strict boolean
Default: true

If false, determines the file type by extension. The default value is true.

Examples
Sample code invoking the fileGetMimeType function

Assume that you have a file named test.pdf in temp directory and test.txt in the same folder, and you want to check the MIME type. Here test.txt is a copy of test.pdf with extension renamed to txt.

<cfscript>
	mimeTypes = '';
	mimeTypes = listAppend(mimeTypes, fileGetMimeType(expandPath('/folder1/test.pdf')));
	mimeTypes = listAppend(mimeTypes, fileGetMimeType(expandPath('/folder1/test.pdf'),false));
	mimeTypes = listAppend(mimeTypes, fileGetMimeType(expandPath('/folder1/test.txt')));
	mimeTypes = listAppend(mimeTypes, fileGetMimeType(expandPath('/folder1/test.txt'),false));
	writeOutput(mimeTypes);
</cfscript>

Expected Result: application/pdf,application/pdf,text/plain,text/plain

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub