From: Zeev Suraski Date: Fri, 8 Sep 2000 21:56:47 +0000 (+0000) Subject: - Implemented is_upload_file() X-Git-Tag: php-4.0.3RC1~239 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75086e3088ab06fbb2415e15490c216ac7c9c8b9;p=php - Implemented is_upload_file() --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 02101d60f7..77374bdeed 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -356,6 +356,8 @@ function_entry basic_functions[] = { PHP_FE(parse_ini_file, NULL) + PHP_FE(is_upload_file, NULL) + /* functions from reg.c */ PHP_FE(ereg, third_argument_force_ref) PHP_FE(ereg_replace, NULL) @@ -2205,6 +2207,27 @@ PHPAPI PHP_FUNCTION(warn_not_available) } +PHP_FUNCTION(is_upload_file) +{ + zval **path; + SLS_FETCH(); + + if (!SG(rfc1867_uploaded_files)) { + RETURN_FALSE; + } + + if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &path)!=SUCCESS) { + ZEND_WRONG_PARAM_COUNT(); + } + convert_to_string_ex(path); + + if (zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} + /* * Local variables: * tab-width: 4 diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index bf9e1b8dcd..e705a6de2a 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -109,6 +109,8 @@ PHP_FUNCTION(get_extension_funcs); PHP_FUNCTION(register_tick_function); PHP_FUNCTION(unregister_tick_function); +PHP_FUNCTION(is_upload_file); + /* From the INI parser */ PHP_FUNCTION(parse_ini_file); diff --git a/main/SAPI.c b/main/SAPI.c index 8e838c526e..cee1f77876 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -301,6 +301,7 @@ SAPI_API void sapi_activate(SLS_D) sapi_module.activate(SLS_C); } } + SG(rfc1867_uploaded_files) = NULL; } @@ -325,6 +326,10 @@ SAPI_API void sapi_deactivate(SLS_D) if (sapi_module.deactivate) { sapi_module.deactivate(SLS_C); } + if (SG(rfc1867_uploaded_files)) { + zend_hash_destroy(SG(rfc1867_uploaded_files)); + FREE_HASHTABLE(SG(rfc1867_uploaded_files)); + } } diff --git a/main/SAPI.h b/main/SAPI.h index 18fcbbff66..d1cef23f7b 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -100,7 +100,7 @@ typedef struct { struct stat global_stat; char *default_mimetype; char *default_charset; - HashTable *rfc_1867_uploaded_files; + HashTable *rfc1867_uploaded_files; } sapi_globals_struct; diff --git a/main/rfc1867.c b/main/rfc1867.c index bdff72a2b6..68af24557c 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -86,7 +86,7 @@ static void register_http_post_files_variable_ex(char *var, zval *val, zval *htt /* * Split raw mime stream up into appropriate components */ -static void php_mime_split(char *buf, int cnt, char *boundary, zval *array_ptr) +static void php_mime_split(char *buf, int cnt, char *boundary, zval *array_ptr SLS_DC) { char *ptr, *loc, *loc2, *loc3, *s, *name, *filename, *u, *fn; int len, state = 0, Done = 0, rem, urem; @@ -102,6 +102,9 @@ static void php_mime_split(char *buf, int cnt, char *boundary, zval *array_ptr) zend_hash_init(&PG(rfc1867_protected_variables), 5, NULL, NULL, 0); + ALLOC_HASHTABLE(SG(rfc1867_uploaded_files)); + zend_hash_init(SG(rfc1867_uploaded_files), 5, NULL, NULL, 0); + ALLOC_ZVAL(http_post_files); array_init(http_post_files); INIT_PZVAL(http_post_files); @@ -348,6 +351,11 @@ static void php_mime_split(char *buf, int cnt, char *boundary, zval *array_ptr) } add_protected_variable(namebuf PLS_CC); safe_php_register_variable(namebuf, fn, NULL, 1 ELS_CC PLS_CC); + { + int dummy=1; + + zend_hash_add(SG(rfc1867_uploaded_files), namebuf, strlen(namebuf)+1, &dummy, sizeof(int), NULL); + } /* Add $foo[tmp_name] */ if(is_arr_upload) { @@ -404,7 +412,7 @@ SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) boundary_len = strlen(boundary); if (SG(request_info).post_data) { - php_mime_split(SG(request_info).post_data, SG(request_info).post_data_length, boundary, array_ptr); + php_mime_split(SG(request_info).post_data, SG(request_info).post_data_length, boundary, array_ptr SLS_CC); } }