char *ct = NULL;
#ifdef HTTP_HAVE_MAGIC
- struct magic_set *magic = magic_open(magicmode);
+ /* magic_load() fails if MAGIC_MIME is set because it
+ cowardly adds .mime to the file name */
+ struct magic_set *magic = magic_open(magicmode &~ MAGIC_MIME);
if (!magic) {
http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid magic mode: %ld", magicmode);
} else if (-1 == magic_load(magic, magicfile)) {
- http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to load magic database '%s'", magicfile);
+ http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to load magic database '%s' (%s)", magicfile, magic_error(magic));
} else {
const char *ctype = NULL;
+ magic_setflags(magic, magicmode);
+
switch (data_mode)
{
case SEND_RSRC:
}
/* }}} */
-/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, long magic_mode])
+/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, long magic_mode = MAGIC_MIME])
*
* Attempts to guess the content type of supplied payload through libmagic.
*/
RETVAL_NULL();
+#ifdef HTTP_HAVE_MAGIC
+ magic_mode = MAGIC_MIME;
+
SET_EH_THROW_HTTP();
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) {
switch (Z_LVAL_P(GET_STATIC_PROP(mode))) {
}
}
SET_EH_NORMAL();
+#endif
}
/* }}} */