Loading...
Searching...
No Matches
Misc MIME Functions

## Functions

string | Mime::get_mime_type_from_ext (string path, string def_type=MimeTypeUnknown)
| returns the mime type for the given filename from the extension or the default type if the extension is not present or unknown
bool | Mime::is_filename_text (string path)
| Returns True if the given filename / path is known to provide text content, False if not.
bool | Mime::is_mime_text (string mime)
string | Mime::mime_decode_urlencoded_string (string str)
| decodes the given string from URL encoded format
string | Mime::mime_get_form_urlencoded_string (hash< auto > h)
| returns a string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data)
string | Mime::mime_get_urlencoded_string (auto val)
| Returns a single string in MIME URL encoded format.
hash< auto > | Mime::mime_parse_form_urlencoded_string (string str)
| returns a hash corresponding to the string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data)

## Detailed Description

## Function Documentation

## is_filename_text()

bool Mime::is_filename_text | ( | string | path | ) |

Returns True if the given filename / path is known to provide text content, False if not.

Parameters

  path | The filename or path to test

Returns
  True if the given filename / path is known to provide text content, False if not

Since
  Mime 1.6

## is_mime_text()

bool Mime::is_mime_text | ( | string | mime | ) |

Returns True if the given MIME type is known to provide text content, False if not

Parameters

  mime | The MIME type to test

Returns
  True if the given MIME type is known to provide text content, False if not

Since
  Mime 1.6

## mime_decode_urlencoded_string()

string Mime::mime_decode_urlencoded_string | ( | string | str | ) |

decodes the given string from URL encoded format

Parameters

  str | the URL encoded string to decode

Returns
  the decoded string

See also
  RFC 2738 2.2

Since
  - Mime 1.3.4.1
  - Mime 1.4.1 this function is a wrapper for builtin function decode_url()

## mime_get_form_urlencoded_string()

string Mime::mime_get_form_urlencoded_string | ( | hash< auto > | h | ) |

returns a string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data)

Parameters will be separated by `"&"` characters. All key values must be strings or convertible to strings or a URLENCODED-TYPE-ERROR exception is thrown

Parameters

  h | the hash to use to generate the string

Returns
  a string in `application/x-www-form-urlencoded` format

Exceptions

  URLENCODED-TYPE-ERROR | hash value cannot be converted to a string
  INVALID-CHARACTER | an invalid character has been found

See also
  RFC 2738 2.2

Since
  Mime 1.3.4.1

## mime_get_urlencoded_string()

string Mime::mime_get_urlencoded_string | ( | auto | val | ) |

Returns a single string in MIME URL encoded format.

The string is converted to UTF-8, if necessary, and then the encoded version is returned; reserved characters are replaced with percent encoding, characters outside the ASCII character are encoded with their UTF-8 bytes with binary encoding (ex: "%C3%B6" for "ö")

Parameters

  val | the input value

Returns
  the output string in MIME URL encoded format

Exceptions

  INVALID-VALUE | the value given cannot be converted to a string

See also
  RFC 2738 2.2

Note
  spaces are not replaced with `'+'` signs but rather encoded as `%20` because `'+'` signs are often encoded and decoded improperly in URLs, and `%20` is unambiguous

Since
  Mime 1.3.4.1

## mime_parse_form_urlencoded_string()

hash< auto > Mime::mime_parse_form_urlencoded_string | ( | string | str | ) |

returns a hash corresponding to the string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data)

Parameters

  str | the string to parse

Returns
  the hash corresponding to the string, where values are always of type *string unlessa key is repeated, in which case the key's value will be a list of all elements provided

Exceptions

  URLENCODED-PARSE-ERROR | cannot parse the given string

See also
  RFC 2738 2.2

Since
  Mime 1.3.4.1