cr_filename_to_mime_type (public)

 cr_filename_to_mime_type [ -create ] filename

Defined in packages/acs-content-repository/tcl/revision-procs.tcl

given a filename, returns the mime type. If the -create flag is given the mime type will be created; this assumes there is some other way such as ns_guesstype to find the filename

Switches:
-create
(boolean) (optional)
flag whether to create the mime type the routine picks for filename
Parameters:
filename - the filename to try to guess a mime type for (the file need not exist, the routine does not attempt to access the file in any way)
Returns:
mimetype (or */* of unknown)
Author:
Jeff Davis <davis@xarg.net>

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_authenticate auth_authenticate (test acs-authentication) cr_filename_to_mime_type cr_filename_to_mime_type test_auth_authenticate->cr_filename_to_mime_type cr_create_mime_type cr_create_mime_type (private) cr_filename_to_mime_type->cr_create_mime_type db_0or1row db_0or1row (public) cr_filename_to_mime_type->db_0or1row acs_mail_lite::send_immediately acs_mail_lite::send_immediately (private) acs_mail_lite::send_immediately->cr_filename_to_mime_type cr_check_mime_type cr_check_mime_type (public) cr_check_mime_type->cr_filename_to_mime_type download_insert_revision download_insert_revision (public) download_insert_revision->cr_filename_to_mime_type email_image::edit_email_image email_image::edit_email_image (public) email_image::edit_email_image->cr_filename_to_mime_type email_image::new_item email_image::new_item (public) email_image::new_item->cr_filename_to_mime_type

Testcases:
auth_authenticate
Source code:
    set extension [string tolower [string trimleft [file extension $filename"."]]

    if {$extension eq ""} {
        return "*/*"
    }

    if {[db_0or1row lookup_mimetype {
        select mime_type
          from cr_extension_mime_type_map
         where extension = :extension
    }]} {
        return $mime_type
    } else {
        set mime_type [string tolower [ns_guesstype $filename]]

        ns_log Debug "guessed mime \"$mime_type\" create_p $create_p"
        if {(!$create_p) || $mime_type eq "*/*" || $mime_type eq ""} {
            # we don't have anything meaningful for this mimetype
            # so just */* it.

            return "*/*"
        }

        # We guessed a type but there was no mapping
        # create it and map it.  We know the extension
        cr_create_mime_type -extension $extension -mime_type $mime_type -description {}

        return $mime_type
    }
XQL Not present:
Generic
PostgreSQL XQL file:
packages/acs-content-repository/tcl/revision-procs-postgresql.xql

Oracle XQL file:
packages/acs-content-repository/tcl/revision-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: