+ * Attempts to guess the content type of supplied payload through libmagic.
+ * If the attempt is successful, the guessed content type will automatically
+ * be set as response content type.
+ *
+ * Expects a string parameter specifying the magic.mime database to use.
+ * Additionally accepts an optional int parameter, being flags for libmagic.
+ *
+ * Returns the guessed content type on success, or FALSE on failure.
+ *
+ * Throws HttpRuntimeException, HttpInvalidParamException
+ * if http.only_exceptions is TRUE.
+ */
+PHP_METHOD(HttpResponse, guessContentType)
+{
+ char *magic_file, *ct = NULL;
+ int magic_file_len;
+ long magic_mode = 0;
+
+ RETVAL_FALSE;
+
+#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))) {
+ case SEND_DATA:
+ {
+ zval *data = GET_STATIC_PROP(data);
+ ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(data), Z_STRLEN_P(data), SEND_DATA);
+ }
+ break;
+
+ case SEND_RSRC:
+ {
+ php_stream *s;
+ zval *z = GET_STATIC_PROP(stream);
+ z->type = IS_RESOURCE;
+ php_stream_from_zval(s, &z);
+ ct = http_guess_content_type(magic_file, magic_mode, s, 0, SEND_RSRC);
+ }
+ break;
+
+ default:
+ ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(GET_STATIC_PROP(file)), 0, -1);
+ break;
+ }
+ if (ct) {
+ UPD_STATIC_PROP(string, contentType, ct);
+ RETVAL_STRING(ct, 0);
+ }
+ }
+ SET_EH_NORMAL();
+#else
+ http_error(HE_THROW, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
+#endif
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::setContentDisposition(string filename[, bool inline = false])
+ *
+ * Set the Content-Disposition. The Content-Disposition header is very useful
+ * if the data actually sent came from a file or something similar, that should
+ * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
+ *
+ * Expects a string parameter specifying the file name the "Save as..." dialog
+ * should display. Optionally accepts a bool parameter, which, if set to true
+ * and the user agent knows how to handle the content type, will probably not
+ * cause the popup window to be shown.
+ *
+ * Returns TRUE on success or FALSE on failure.