1999-06-12 17:50:39 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
1999-07-16 13:13:16 +00:00
| PHP version 4.0 |
1999-06-12 17:50:39 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2001-02-26 06:11:02 +00:00
| Copyright ( c ) 1997 - 2001 The PHP Group |
1999-06-12 17:50:39 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2000-05-18 15:34:45 +00:00
| This source file is subject to version 2.02 of the PHP license , |
1999-07-16 13:13:16 +00:00
| that is bundled with this package in the file LICENSE , and is |
| available at through the world - wide - web at |
2000-05-18 15:34:45 +00:00
| http : //www.php.net/license/2_02.txt. |
1999-07-16 13:13:16 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
1999-06-12 17:50:39 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2000-06-04 05:46:28 +00:00
| Authors : Rasmus Lerdorf < rasmus @ php . net > |
1999-06-12 17:50:39 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
# include <stdio.h>
# include "php.h"
2000-09-11 18:56:47 +00:00
# include "php_open_temporary_file.h"
1999-06-12 17:50:39 +00:00
# include "zend_globals.h"
# include "php_globals.h"
2000-01-28 17:24:53 +00:00
# include "php_variables.h"
1999-05-25 22:28:24 +00:00
# include "rfc1867.h"
2000-10-17 18:13:35 +00:00
# include "ext/standard/type.h"
1999-05-25 22:28:24 +00:00
1999-06-12 17:50:39 +00:00
# define NEW_BOUNDARY_CHECK 1
2000-09-04 19:07:50 +00:00
# define SAFE_RETURN { if (namebuf) efree(namebuf); if (filenamebuf) efree(filenamebuf); if (lbuf) efree(lbuf); if (abuf) efree(abuf); if(arr_index) efree(arr_index); zend_hash_destroy(&PG(rfc1867_protected_variables)); return; }
1999-06-12 17:50:39 +00:00
2000-04-02 21:27:32 +00:00
/* The longest property name we use in an uploaded file array */
2000-04-02 22:15:14 +00:00
# define MAX_SIZE_OF_INDEX sizeof("[tmp_name]")
2000-04-02 21:27:32 +00:00
2000-09-04 19:07:50 +00:00
static void add_protected_variable ( char * varname PLS_DC )
{
2000-09-04 21:23:41 +00:00
int dummy = 1 ;
2000-09-04 19:07:50 +00:00
zend_hash_add ( & PG ( rfc1867_protected_variables ) , varname , strlen ( varname ) + 1 , & dummy , sizeof ( int ) , NULL ) ;
}
static zend_bool is_protected_variable ( char * varname PLS_DC )
{
return zend_hash_exists ( & PG ( rfc1867_protected_variables ) , varname , strlen ( varname ) + 1 ) ;
}
2000-09-04 22:26:01 +00:00
static void safe_php_register_variable ( char * var , char * strval , zval * track_vars_array , zend_bool override_protection ELS_DC PLS_DC )
2000-09-04 19:07:50 +00:00
{
2000-09-04 22:26:01 +00:00
if ( override_protection | | ! is_protected_variable ( var PLS_CC ) ) {
2000-09-04 19:07:50 +00:00
php_register_variable ( var , strval , track_vars_array ELS_CC PLS_CC ) ;
}
}
2000-09-04 22:26:01 +00:00
static void safe_php_register_variable_ex ( char * var , zval * val , pval * track_vars_array , zend_bool override_protection ELS_DC PLS_DC )
2000-09-04 19:07:50 +00:00
{
2000-09-04 22:26:01 +00:00
if ( override_protection | | ! is_protected_variable ( var PLS_CC ) ) {
2000-09-04 19:07:50 +00:00
php_register_variable_ex ( var , val , track_vars_array ELS_CC PLS_CC ) ;
}
}
2000-02-19 20:12:26 +00:00
2000-09-04 22:26:01 +00:00
static void register_http_post_files_variable ( char * strvar , char * val , zval * http_post_files , zend_bool override_protection ELS_DC PLS_DC )
2000-02-19 20:12:26 +00:00
{
int register_globals = PG ( register_globals ) ;
2000-09-04 19:07:50 +00:00
2000-02-19 20:12:26 +00:00
PG ( register_globals ) = 0 ;
2000-09-04 22:26:01 +00:00
safe_php_register_variable ( strvar , val , http_post_files , override_protection ELS_CC PLS_CC ) ;
2000-02-19 20:12:26 +00:00
PG ( register_globals ) = register_globals ;
}
2000-09-04 22:26:01 +00:00
static void register_http_post_files_variable_ex ( char * var , zval * val , zval * http_post_files , zend_bool override_protection ELS_DC PLS_DC )
2000-02-19 20:12:26 +00:00
{
int register_globals = PG ( register_globals ) ;
2000-09-04 19:07:50 +00:00
2000-02-19 20:12:26 +00:00
PG ( register_globals ) = 0 ;
2000-09-04 22:26:01 +00:00
safe_php_register_variable_ex ( var , val , http_post_files , override_protection ELS_CC PLS_CC ) ;
2000-02-19 20:12:26 +00:00
PG ( register_globals ) = register_globals ;
}
2000-09-09 11:41:14 +00:00
static int unlink_filename ( char * * filename )
{
2001-04-30 12:45:02 +00:00
VCWD_UNLINK ( * filename ) ;
2000-09-09 11:41:14 +00:00
return 0 ;
}
void destroy_uploaded_files_hash ( SLS_D )
{
zend_hash_apply ( SG ( rfc1867_uploaded_files ) , ( apply_func_t ) unlink_filename ) ;
zend_hash_destroy ( SG ( rfc1867_uploaded_files ) ) ;
FREE_HASHTABLE ( SG ( rfc1867_uploaded_files ) ) ;
}
1999-06-12 17:50:39 +00:00
/*
* Split raw mime stream up into appropriate components
*/
2000-09-09 15:02:15 +00:00
static void php_mime_split ( char * buf , int cnt , char * boundary , zval * array_ptr SLS_DC PLS_DC )
1999-06-12 17:50:39 +00:00
{
2000-09-09 11:41:14 +00:00
char * ptr , * loc , * loc2 , * loc3 , * s , * name , * filename , * u , * temp_filename ;
1999-06-12 17:50:39 +00:00
int len , state = 0 , Done = 0 , rem , urem ;
2000-02-12 17:37:11 +00:00
int eolsize ;
1999-06-12 17:50:39 +00:00
long bytes , max_file_size = 0 ;
2000-06-04 05:46:28 +00:00
char * namebuf = NULL , * filenamebuf = NULL , * lbuf = NULL ,
2000-09-04 19:07:50 +00:00
* abuf = NULL , * start_arr = NULL , * end_arr = NULL , * arr_index = NULL ;
1999-06-12 17:50:39 +00:00
FILE * fp ;
2000-06-04 05:46:28 +00:00
int itype , is_arr_upload = 0 , arr_len = 0 ;
2000-02-19 20:12:26 +00:00
zval * http_post_files = NULL ;
2000-09-09 11:41:14 +00:00
zend_bool upload_successful ;
zend_bool magic_quotes_gpc ;
1999-06-12 17:50:39 +00:00
ELS_FETCH ( ) ;
2000-09-04 19:07:50 +00:00
zend_hash_init ( & PG ( rfc1867_protected_variables ) , 5 , NULL , NULL , 0 ) ;
2000-09-08 21:56:47 +00:00
ALLOC_HASHTABLE ( SG ( rfc1867_uploaded_files ) ) ;
2001-01-15 10:50:39 +00:00
zend_hash_init ( SG ( rfc1867_uploaded_files ) , 5 , NULL , ( dtor_func_t ) free_estring , 0 ) ;
2000-09-08 21:56:47 +00:00
2000-09-05 19:06:29 +00:00
ALLOC_ZVAL ( http_post_files ) ;
array_init ( http_post_files ) ;
INIT_PZVAL ( http_post_files ) ;
2000-09-07 04:12:31 +00:00
PG ( http_globals ) [ TRACK_VARS_FILES ] = http_post_files ;
2000-02-19 20:12:26 +00:00
1999-06-12 17:50:39 +00:00
ptr = buf ;
rem = cnt ;
len = strlen ( boundary ) ;
while ( ( ptr - buf < cnt ) & & ! Done ) {
switch ( state ) {
case 0 : /* Looking for mime boundary */
loc = memchr ( ptr , * boundary , cnt ) ;
if ( loc ) {
if ( ! strncmp ( loc , boundary , len ) ) {
state = 1 ;
2000-02-12 17:37:11 +00:00
eolsize = 2 ;
2000-02-15 22:51:18 +00:00
if ( * ( loc + len ) = = 0x0a ) {
2000-02-12 17:37:11 +00:00
eolsize = 1 ;
2000-02-15 22:51:18 +00:00
}
2000-02-12 17:37:11 +00:00
rem - = ( loc - ptr ) + len + eolsize ;
ptr = loc + len + eolsize ;
1999-06-12 17:50:39 +00:00
} else {
rem - = ( loc - ptr ) + 1 ;
ptr = loc + 1 ;
}
} else {
Done = 1 ;
}
break ;
case 1 : /* Check content-disposition */
2001-05-02 01:18:53 +00:00
while ( strncasecmp ( ptr , " Content-Disposition: form-data; " , 31 ) ) {
1999-06-12 17:50:39 +00:00
if ( rem < 31 ) {
SAFE_RETURN ;
}
2001-05-02 01:18:53 +00:00
if ( ptr [ 1 ] = = ' \n ' ) {
2001-07-16 20:42:49 +00:00
/* empty line as end of header found */
2001-05-02 01:18:53 +00:00
php_error ( E_WARNING , " File Upload Mime headers garbled ptr: [%c%c%c%c%c] " , * ptr , * ( ptr + 1 ) , * ( ptr + 2 ) , * ( ptr + 3 ) , * ( ptr + 4 ) ) ;
SAFE_RETURN ;
2001-07-16 20:42:49 +00:00
}
2001-05-02 01:18:53 +00:00
/* some other headerfield found, skip it */
2001-07-16 20:42:49 +00:00
loc = ( char * ) memchr ( ptr , ' \n ' , rem ) + 1 ;
2001-07-16 20:43:18 +00:00
while ( * loc = = ' ' | | * loc = = ' \t ' ) {
2001-05-02 01:18:53 +00:00
/* other field is folded, skip it */
2001-07-16 20:43:18 +00:00
loc = ( char * ) memchr ( loc , ' \n ' , rem - ( loc - ptr ) ) + 1 ;
}
2001-05-02 01:18:53 +00:00
rem - = ( loc - ptr ) ;
ptr = loc ;
1999-06-12 17:50:39 +00:00
}
loc = memchr ( ptr , ' \n ' , rem ) ;
2001-07-16 20:42:49 +00:00
while ( loc [ 1 ] = = ' ' | | loc [ 1 ] = = ' \t ' ) {
2001-05-02 01:18:53 +00:00
/* field is folded, look for end */
loc = memchr ( loc + 1 , ' \n ' , rem - ( loc - ptr ) - 1 ) ;
2001-07-16 20:42:49 +00:00
}
2001-01-03 10:52:26 +00:00
name = strstr ( ptr , " name= " ) ;
1999-06-12 17:50:39 +00:00
if ( name & & name < loc ) {
2001-01-03 10:52:26 +00:00
name + = 6 ;
2001-05-02 01:18:53 +00:00
if ( * name = = ' \" ' ) {
2001-01-03 10:52:26 +00:00
name + + ;
s = memchr ( name , ' \" ' , loc - name ) ;
if ( ! s ) {
php_error ( E_WARNING , " File Upload Mime headers garbled name: [%c%c%c%c%c] " , * name , * ( name + 1 ) , * ( name + 2 ) , * ( name + 3 ) , * ( name + 4 ) ) ;
SAFE_RETURN ;
}
} else {
2001-05-02 01:18:53 +00:00
s = strpbrk ( name , " \t ()<>@,;: \\ \" /[]?= \r \n " ) ;
1999-06-12 17:50:39 +00:00
}
if ( namebuf ) {
efree ( namebuf ) ;
}
namebuf = estrndup ( name , s - name ) ;
if ( lbuf ) {
efree ( lbuf ) ;
}
2000-12-08 14:28:14 +00:00
lbuf = emalloc ( s - name + MAX_SIZE_OF_INDEX + 1 ) ;
1999-06-12 17:50:39 +00:00
state = 2 ;
2001-05-02 01:18:53 +00:00
loc2 = loc ;
while ( loc2 [ 2 ] ! = ' \n ' ) {
/* empty line as end of header not yet found */
loc2 = memchr ( loc2 + 1 , ' \n ' , rem - ( loc2 - ptr ) - 1 ) ;
}
rem - = ( loc2 - ptr ) + 3 ;
ptr = loc2 + 3 ;
2000-06-04 05:46:28 +00:00
/* is_arr_upload is true when name of file upload field
* ends in [ . * ]
* start_arr is set to point to 1 st [
* end_arr points to last ]
*/
2001-01-19 15:39:35 +00:00
is_arr_upload = ( start_arr = strchr ( namebuf , ' [ ' ) ) & &
2000-06-04 05:46:28 +00:00
( end_arr = strrchr ( namebuf , ' ] ' ) ) & &
( end_arr = namebuf + strlen ( namebuf ) - 1 ) ;
if ( is_arr_upload ) {
arr_len = strlen ( start_arr ) ;
if ( arr_index ) efree ( arr_index ) ;
2001-01-13 10:19:17 +00:00
arr_index = estrndup ( start_arr + 1 , arr_len - 2 ) ;
2000-06-04 05:46:28 +00:00
}
1999-06-12 17:50:39 +00:00
} else {
1999-08-02 19:17:14 +00:00
php_error ( E_WARNING , " File upload error - no name component in content disposition " ) ;
1999-06-12 17:50:39 +00:00
SAFE_RETURN ;
}
2001-06-19 16:54:30 +00:00
filename = strstr ( s , " filename= \" " ) ;
1999-06-12 17:50:39 +00:00
if ( filename & & filename < loc ) {
2001-06-19 16:54:30 +00:00
filename + = 10 ;
1999-06-12 17:50:39 +00:00
s = memchr ( filename , ' \" ' , loc - filename ) ;
if ( ! s ) {
2000-08-06 06:40:28 +00:00
php_error ( E_WARNING , " File Upload Mime headers garbled filename: [%c%c%c%c%c] " , * filename , * ( filename + 1 ) , * ( filename + 2 ) , * ( filename + 3 ) , * ( filename + 4 ) ) ;
1999-06-12 17:50:39 +00:00
SAFE_RETURN ;
}
if ( filenamebuf ) {
efree ( filenamebuf ) ;
}
filenamebuf = estrndup ( filename , s - filename ) ;
2000-02-19 20:12:26 +00:00
/* Add $foo_name */
2000-06-04 05:46:28 +00:00
if ( is_arr_upload ) {
if ( abuf ) {
efree ( abuf ) ;
}
abuf = estrndup ( namebuf , strlen ( namebuf ) - arr_len ) ;
sprintf ( lbuf , " %s_name[%s] " , abuf , arr_index ) ;
} else {
sprintf ( lbuf , " %s_name " , namebuf ) ;
}
1999-06-12 17:50:39 +00:00
s = strrchr ( filenamebuf , ' \\ ' ) ;
if ( s & & s > filenamebuf ) {
2000-09-04 22:26:01 +00:00
safe_php_register_variable ( lbuf , s + 1 , NULL , 0 ELS_CC PLS_CC ) ;
1999-06-12 17:50:39 +00:00
} else {
2000-09-04 22:26:01 +00:00
safe_php_register_variable ( lbuf , filenamebuf , NULL , 0 ELS_CC PLS_CC ) ;
1999-06-12 17:50:39 +00:00
}
2000-02-19 20:12:26 +00:00
/* Add $foo[name] */
2001-06-19 16:54:30 +00:00
if ( is_arr_upload ) {
sprintf ( lbuf , " %s[name][%s] " , abuf , arr_index ) ;
} else {
sprintf ( lbuf , " %s[name] " , namebuf ) ;
}
2000-02-19 20:12:26 +00:00
if ( s & & s > filenamebuf ) {
2000-09-04 22:26:01 +00:00
register_http_post_files_variable ( lbuf , s + 1 , http_post_files , 0 ELS_CC PLS_CC ) ;
2000-02-19 20:12:26 +00:00
} else {
2000-09-04 22:26:01 +00:00
register_http_post_files_variable ( lbuf , filenamebuf , http_post_files , 0 ELS_CC PLS_CC ) ;
2000-02-19 20:12:26 +00:00
}
1999-06-12 17:50:39 +00:00
state = 3 ;
2000-07-30 11:22:18 +00:00
s = " " ;
1999-06-12 17:50:39 +00:00
if ( ( loc2 - loc ) > 2 ) {
if ( ! strncasecmp ( loc + 1 , " Content-Type: " , 13 ) ) {
* ( loc2 - 1 ) = ' \0 ' ;
2000-07-30 11:22:18 +00:00
s = loc + 15 ;
1999-06-12 17:50:39 +00:00
}
2000-08-06 06:40:28 +00:00
loc3 = memchr ( loc2 + 1 , ' \n ' , rem - 1 ) ;
if ( loc3 = = NULL ) {
php_error ( E_WARNING , " File Upload Mime headers garbled header3: [%c%c%c%c%c] " , * loc2 , * ( loc2 + 1 ) , * ( loc2 + 2 ) , * ( loc2 + 3 ) , * ( loc2 + 4 ) ) ;
SAFE_RETURN ;
}
if ( loc3 - loc2 > 2 ) { /* we have a third header */
rem - = ( ptr - loc3 ) + 3 ;
ptr = loc3 + 3 ;
} else {
rem - = ( ptr - loc3 ) + 1 ;
ptr = loc3 + 1 ;
}
1999-06-12 17:50:39 +00:00
}
2000-07-30 11:22:18 +00:00
/* Add $foo_type */
if ( is_arr_upload ) {
sprintf ( lbuf , " %s_type[%s] " , abuf , arr_index ) ;
} else {
sprintf ( lbuf , " %s_type " , namebuf ) ;
}
2000-09-04 22:26:01 +00:00
safe_php_register_variable ( lbuf , s , NULL , 0 ELS_CC PLS_CC ) ;
2000-07-30 11:22:18 +00:00
/* Add $foo[type] */
if ( is_arr_upload ) {
sprintf ( lbuf , " %s[type][%s] " , abuf , arr_index ) ;
} else {
sprintf ( lbuf , " %s[type] " , namebuf ) ;
}
2000-09-04 22:26:01 +00:00
register_http_post_files_variable ( lbuf , s , http_post_files , 0 ELS_CC PLS_CC ) ;
2000-07-30 11:22:18 +00:00
if ( * s ! = ' \0 ' ) {
* ( loc2 - 1 ) = ' \n ' ;
}
1999-06-12 17:50:39 +00:00
}
break ;
case 2 : /* handle form-data fields */
loc = memchr ( ptr , * boundary , rem ) ;
u = ptr ;
while ( loc ) {
if ( ! strncmp ( loc , boundary , len ) )
break ;
u = loc + 1 ;
urem = rem - ( loc - ptr ) - 1 ;
loc = memchr ( u , * boundary , urem ) ;
}
if ( ! loc ) {
1999-08-02 19:17:14 +00:00
php_error ( E_WARNING , " File Upload Field Data garbled " ) ;
1999-06-12 17:50:39 +00:00
SAFE_RETURN ;
}
* ( loc - 4 ) = ' \0 ' ;
2000-09-04 05:09:46 +00:00
/* Check to make sure we are not overwriting special file
* upload variables */
2000-09-04 22:26:01 +00:00
safe_php_register_variable ( namebuf , ptr , array_ptr , 0 ELS_CC PLS_CC ) ;
1999-06-12 17:50:39 +00:00
/* And a little kludge to pick out special MAX_FILE_SIZE */
1999-12-17 19:51:39 +00:00
itype = php_check_ident_type ( namebuf ) ;
1999-06-12 17:50:39 +00:00
if ( itype ) {
u = strchr ( namebuf , ' [ ' ) ;
if ( u )
* u = ' \0 ' ;
}
if ( ! strcmp ( namebuf , " MAX_FILE_SIZE " ) ) {
max_file_size = atol ( ptr ) ;
}
if ( itype ) {
if ( u )
* u = ' [ ' ;
}
rem - = ( loc - ptr ) ;
ptr = loc ;
state = 0 ;
break ;
case 3 : /* Handle file */
loc = memchr ( ptr , * boundary , rem ) ;
u = ptr ;
while ( loc ) {
if ( ! strncmp ( loc , boundary , len )
# if NEW_BOUNDARY_CHECK
& & ( loc - 2 > buf & & * ( loc - 2 ) = = ' - ' & & * ( loc - 1 ) = = ' - ' ) /* ensure boundary is prefixed with -- */
& & ( loc - 2 = = buf | | * ( loc - 3 ) = = ' \n ' ) /* ensure beginning of line */
# endif
) {
break ;
}
u = loc + 1 ;
urem = rem - ( loc - ptr ) - 1 ;
loc = memchr ( u , * boundary , urem ) ;
}
if ( ! loc ) {
1999-08-02 19:17:14 +00:00
php_error ( E_WARNING , " File Upload Error - No Mime boundary found after start of file header " ) ;
1999-06-12 17:50:39 +00:00
SAFE_RETURN ;
}
2000-02-19 20:12:26 +00:00
bytes = 0 ;
2000-09-09 11:41:14 +00:00
fp = php_open_temporary_file ( PG ( upload_tmp_dir ) , " php " , & temp_filename ) ;
if ( ! fp ) {
php_error ( E_WARNING , " File upload error - unable to create a temporary file " ) ;
SAFE_RETURN ;
}
1999-06-12 17:50:39 +00:00
if ( ( loc - ptr - 4 ) > PG ( upload_max_filesize ) ) {
1999-08-02 19:17:14 +00:00
php_error ( E_WARNING , " Max file size of %ld bytes exceeded - file [%s] not saved " , PG ( upload_max_filesize ) , namebuf ) ;
2000-09-09 11:41:14 +00:00
upload_successful = 0 ;
1999-06-12 17:50:39 +00:00
} else if ( max_file_size & & ( ( loc - ptr - 4 ) > max_file_size ) ) {
1999-08-02 19:17:14 +00:00
php_error ( E_WARNING , " Max file size exceeded - file [%s] not saved " , namebuf ) ;
2000-09-09 11:41:14 +00:00
upload_successful = 0 ;
1999-06-12 17:50:39 +00:00
} else if ( ( loc - ptr - 4 ) < = 0 ) {
2000-09-09 11:41:14 +00:00
upload_successful = 0 ;
1999-06-12 17:50:39 +00:00
} else {
bytes = fwrite ( ptr , 1 , loc - ptr - 4 , fp ) ;
if ( bytes < ( loc - ptr - 4 ) ) {
1999-08-02 19:17:14 +00:00
php_error ( E_WARNING , " Only %d bytes were written, expected to write %ld " , bytes , loc - ptr - 4 ) ;
1999-06-12 17:50:39 +00:00
}
2000-09-09 11:41:14 +00:00
upload_successful = 1 ;
1999-06-12 17:50:39 +00:00
}
2000-09-09 11:41:14 +00:00
fclose ( fp ) ;
2000-09-04 21:23:41 +00:00
add_protected_variable ( namebuf PLS_CC ) ;
2000-09-09 11:41:14 +00:00
if ( ! upload_successful ) {
2000-10-30 15:30:27 +00:00
if ( temp_filename ) {
unlink ( temp_filename ) ;
efree ( temp_filename ) ;
}
2000-09-09 11:41:14 +00:00
temp_filename = " none " ;
} else {
zend_hash_add ( SG ( rfc1867_uploaded_files ) , temp_filename , strlen ( temp_filename ) + 1 , & temp_filename , sizeof ( char * ) , NULL ) ;
2000-09-08 21:56:47 +00:00
}
2000-04-02 21:27:32 +00:00
2000-09-09 11:41:14 +00:00
magic_quotes_gpc = PG ( magic_quotes_gpc ) ;
PG ( magic_quotes_gpc ) = 0 ;
safe_php_register_variable ( namebuf , temp_filename , NULL , 1 ELS_CC PLS_CC ) ;
2000-04-02 21:27:32 +00:00
/* Add $foo[tmp_name] */
2000-06-04 05:46:28 +00:00
if ( is_arr_upload ) {
sprintf ( lbuf , " %s[tmp_name][%s] " , abuf , arr_index ) ;
} else {
sprintf ( lbuf , " %s[tmp_name] " , namebuf ) ;
}
2000-09-04 22:05:00 +00:00
add_protected_variable ( lbuf PLS_CC ) ;
2000-09-09 11:41:14 +00:00
register_http_post_files_variable ( lbuf , temp_filename , http_post_files , 1 ELS_CC PLS_CC ) ;
PG ( magic_quotes_gpc ) = magic_quotes_gpc ;
2000-02-19 20:12:26 +00:00
{
zval file_size ;
file_size . value . lval = bytes ;
file_size . type = IS_LONG ;
/* Add $foo_size */
2000-06-04 05:46:28 +00:00
if ( is_arr_upload ) {
sprintf ( lbuf , " %s_size[%s] " , abuf , arr_index ) ;
} else {
sprintf ( lbuf , " %s_size " , namebuf ) ;
}
2000-09-04 22:26:01 +00:00
safe_php_register_variable_ex ( lbuf , & file_size , NULL , 0 ELS_CC PLS_CC ) ;
2000-02-19 20:12:26 +00:00
/* Add $foo[size] */
2000-06-04 05:46:28 +00:00
if ( is_arr_upload ) {
sprintf ( lbuf , " %s[size][%s] " , abuf , arr_index ) ;
} else {
sprintf ( lbuf , " %s[size] " , namebuf ) ;
}
2000-09-04 22:26:01 +00:00
register_http_post_files_variable_ex ( lbuf , & file_size , http_post_files , 0 ELS_CC PLS_CC ) ;
2000-02-19 20:12:26 +00:00
}
1999-06-12 17:50:39 +00:00
state = 0 ;
rem - = ( loc - ptr ) ;
ptr = loc ;
break ;
}
}
SAFE_RETURN ;
}
2000-02-17 20:23:59 +00:00
SAPI_POST_HANDLER_FUNC ( rfc1867_post_handler )
1999-05-25 22:28:24 +00:00
{
char * boundary ;
uint boundary_len ;
2000-02-17 20:23:59 +00:00
zval * array_ptr = ( zval * ) arg ;
2000-09-09 15:02:15 +00:00
PLS_FETCH ( ) ;
if ( ! PG ( file_uploads ) ) {
php_error ( E_WARNING , " File uploads are disabled " ) ;
return ;
}
1999-05-28 22:41:48 +00:00
1999-05-25 22:28:24 +00:00
boundary = strstr ( content_type_dup , " boundary " ) ;
if ( ! boundary | | ! ( boundary = strchr ( boundary , ' = ' ) ) ) {
sapi_module . sapi_error ( E_COMPILE_ERROR , " Missing boundary in multipart/form-data POST data " ) ;
return ;
}
boundary + + ;
boundary_len = strlen ( boundary ) ;
2000-10-20 23:40:07 +00:00
if ( boundary [ 0 ] = = ' " ' & & boundary [ boundary_len - 1 ] = = ' " ' ) {
boundary + + ;
boundary_len - = 2 ;
boundary [ boundary_len ] = ' \0 ' ;
}
1999-06-12 17:50:39 +00:00
if ( SG ( request_info ) . post_data ) {
2000-09-09 15:02:15 +00:00
php_mime_split ( SG ( request_info ) . post_data , SG ( request_info ) . post_data_length , boundary , array_ptr SLS_CC PLS_CC ) ;
1999-05-25 22:28:24 +00:00
}
}
1999-06-12 17:50:39 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-06-06 13:06:12 +00:00
* vim600 : sw = 4 ts = 4 tw = 78 fdm = marker
* vim < 600 : sw = 4 ts = 4 tw = 78
1999-06-12 17:50:39 +00:00
*/