derick Fri Aug 29 13:29:42 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/fileinfo fileinfo.c php_fileinfo.h
Log:
- MFH: Adding back in mime_content_type().
http://cvs.php.net/viewvc.cgi/php-src/ext/fileinfo/fileinfo.c?r1=1.20.2.6&r2=1.20.2.7&diff_format=u
Index: php-src/ext/fileinfo/fileinfo.c
diff -u php-src/ext/fileinfo/fileinfo.c:1.20.2.6
php-src/ext/fileinfo/fileinfo.c:1.20.2.7
--- php-src/ext/fileinfo/fileinfo.c:1.20.2.6 Wed Aug 27 07:40:44 2008
+++ php-src/ext/fileinfo/fileinfo.c Fri Aug 29 13:29:42 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fileinfo.c,v 1.20.2.6 2008/08/27 07:40:44 tony2001 Exp $ */
+/* $Id: fileinfo.c,v 1.20.2.7 2008/08/29 13:29:42 derick Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -166,6 +166,11 @@
ZEND_ARG_INFO(0, options)
ZEND_ARG_INFO(0, context)
ZEND_END_ARG_INFO()
+
+static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_mime_content_type, 0, 0, 1)
+ ZEND_ARG_INFO(0, string)
+ZEND_END_ARG_INFO()
/* }}} */
/* {{{ finfo_class_functions
@@ -229,6 +234,7 @@
PHP_FE(finfo_set_flags, arginfo_finfo_set_flags)
PHP_FE(finfo_file, arginfo_finfo_file)
PHP_FE(finfo_buffer, arginfo_finfo_buffer)
+ PHP_FE(mime_content_type, arginfo_mime_content_type)
{NULL, NULL, NULL}
};
/* }}} */
@@ -450,7 +456,10 @@
char resolved_path[MAXPATHLEN];
if (*buffer && VCWD_REALPATH(buffer, resolved_path)) {
- ret_val = (char *) magic_file(finfo->magic,
buffer);
+ if ((PG(safe_mode) &&
(!php_checkuid(resolved_path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) ||
php_check_open_basedir(resolved_path TSRMLS_CC)) {
+ RETURN_FALSE;
+ }
+ ret_val = (char *) magic_file(finfo->magic,
resolved_path);
} else {
RETURN_FALSE;
}
@@ -496,6 +505,98 @@
}
/* }}} */
+/* {{{ proto string mime_content_type(string filename|resource stream)
+ Return content-type for file */
+PHP_FUNCTION(mime_content_type)
+{
+ zval *what;
+ magic_t magic;
+ char *tmp, *ret_val;
+ int buffer_len;
+ char *tmp2;
+ php_stream_wrapper *wrap;
+ zval *zcontext = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &what) ==
FAILURE) {
+ return;
+ }
+
+ RETVAL_FALSE;
+
+ magic = magic_open(MAGIC_MIME);
+ if (magic_load(magic, NULL) == -1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to load
magic database.");
+ goto cleanup;
+ }
+
+ switch (Z_TYPE_P(what)) {
+ case IS_STRING:
+ wrap = php_stream_locate_url_wrapper(Z_STRVAL_P(what),
&tmp2, 0 TSRMLS_CC);
+ /* determine if the file is a local file or remote URL
*/
+ if (wrap && wrap->is_url) {
+ php_stream_context *context =
php_stream_context_from_zval(zcontext, 0);
+ php_stream *stream =
php_stream_open_wrapper_ex(Z_STRVAL_P(what), "rb",
+ ENFORCE_SAFE_MODE |
REPORT_ERRORS, NULL, context);
+ if (!stream) {
+ goto cleanup;
+ }
+ buffer_len = php_stream_copy_to_mem(stream,
&tmp, 4096, 0);
+ php_stream_close(stream);
+
+ if (buffer_len == 0) {
+ goto cleanup;
+ }
+ ret_val = (char *) magic_buffer(magic, tmp,
buffer_len);
+ } else { /* local file */
+ char resolved_path[MAXPATHLEN];
+
+ if (Z_STRVAL_P(what) &&
VCWD_REALPATH(Z_STRVAL_P(what), resolved_path)) {
+ if ((PG(safe_mode) &&
(!php_checkuid(resolved_path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) ||
php_check_open_basedir(resolved_path TSRMLS_CC)) {
+ goto cleanup;
+ }
+ ret_val = (char *) magic_file(magic,
resolved_path);
+ } else {
+ goto cleanup;
+ }
+ }
+ break;
+ case IS_RESOURCE:
+ {
+ php_stream *stream;
+ off_t streampos;
+
+ php_stream_from_zval_no_verify(stream, &what);
+ if (!stream) {
+ goto cleanup;
+ }
+ streampos = php_stream_tell(stream); /*
remember stream position for restoration */
+ php_stream_seek(stream, 0, SEEK_SET);
+
+ buffer_len = php_stream_copy_to_mem(stream,
&tmp, 4096, 0);
+ php_stream_seek(stream, streampos, SEEK_SET);
+
+ if (buffer_len == 0) {
+ goto cleanup;
+ }
+ ret_val = (char *) magic_buffer(magic, tmp,
buffer_len);
+ }
+ break;
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only
process string or stream arguments");
+ goto cleanup;
+ }
+ if (!ret_val) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed identify
data %d:%s",
+ magic_errno(magic), magic_error(magic));
+ } else {
+ RETVAL_STRING(ret_val, 1);
+ }
+cleanup:
+ magic_close(magic);
+}
+/* }}} */
+
+
/*
* Local variables:
* tab-width: 4
http://cvs.php.net/viewvc.cgi/php-src/ext/fileinfo/php_fileinfo.h?r1=1.3&r2=1.3.2.1&diff_format=u
Index: php-src/ext/fileinfo/php_fileinfo.h
diff -u php-src/ext/fileinfo/php_fileinfo.h:1.3
php-src/ext/fileinfo/php_fileinfo.h:1.3.2.1
--- php-src/ext/fileinfo/php_fileinfo.h:1.3 Mon Mar 31 09:37:51 2008
+++ php-src/ext/fileinfo/php_fileinfo.h Fri Aug 29 13:29:42 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_fileinfo.h,v 1.3 2008/03/31 09:37:51 sfox Exp $ */
+/* $Id: php_fileinfo.h,v 1.3.2.1 2008/08/29 13:29:42 derick Exp $ */
#ifndef PHP_FILEINFO_H
#define PHP_FILEINFO_H
@@ -43,6 +43,7 @@
PHP_FUNCTION(finfo_set_flags);
PHP_FUNCTION(finfo_file);
PHP_FUNCTION(finfo_buffer);
+PHP_FUNCTION(mime_content_type);
#ifdef ZTS
#define FILEINFO_G(v) TSRMG(fileinfo_globals_id, zend_fileinfo_globals *, v)
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php