sesser          Mon Jan  6 18:51:28 2003 EDT

  Modified files:              
    /php4/main  rfc1867.c 
  Log:
  Adding support for anonymous fileuploads (#21450)
  
  
  
Index: php4/main/rfc1867.c
diff -u php4/main/rfc1867.c:1.130 php4/main/rfc1867.c:1.131
--- php4/main/rfc1867.c:1.130   Tue Dec 31 10:58:54 2002
+++ php4/main/rfc1867.c Mon Jan  6 18:51:28 2003
@@ -16,7 +16,7 @@
    |          Jani Taskinen <[EMAIL PROTECTED]>                              |
    +----------------------------------------------------------------------+
  */
-/* $Id: rfc1867.c,v 1.130 2002/12/31 15:58:54 sebastian Exp $ */
+/* $Id: rfc1867.c,v 1.131 2003/01/06 23:51:28 sesser Exp $ */
 
 /*
  *  This product includes software developed by the Apache Group
@@ -54,6 +54,9 @@
 /* The longest property name we use in an uploaded file array */
 #define MAX_SIZE_OF_INDEX sizeof("[tmp_name]")
 
+/* The longest anonymous name */
+#define MAX_SIZE_ANONNAME 33
+
 /* Errors */
 #define UPLOAD_ERROR_OK   0  /* File upload succesful */
 #define UPLOAD_ERROR_A    1  /* Uploaded file exceeded upload_max_filesize */
@@ -686,7 +689,7 @@
 {
        char *boundary, *s=NULL, *boundary_end = NULL, *start_arr=NULL, 
*array_index=NULL;
        char *temp_filename=NULL, *lbuf=NULL, *abuf=NULL;
-       int boundary_len=0, total_bytes=0, cancel_upload=0, is_arr_upload=0, 
array_len=0, max_file_size=0, skip_upload=0;
+       int boundary_len=0, total_bytes=0, cancel_upload=0, is_arr_upload=0, 
+array_len=0, max_file_size=0, skip_upload=0, anonindex=0, is_anonymous;
        zval *http_post_files=NULL;
        zend_bool magic_quotes_gpc;
        multipart_buffer *mbuff;
@@ -817,13 +820,18 @@
                        }
 
                        /* Return with an error if the posted data is garbled */
-                       if (!param) {
+                       if (!param && !filename) {
                                sapi_module.sapi_error(E_WARNING, "File Upload Mime 
headers garbled");
-                               if (filename) {
-                                       efree(filename);
-                               }
                                SAFE_RETURN;
                        }
+                       
+                       if (!param) {
+                               is_anonymous = 1;
+                               param = emalloc(MAX_SIZE_ANONNAME);
+                               snprintf(param, MAX_SIZE_ANONNAME, "%u", anonindex++);
+                       } else {
+                               is_anonymous = 0;
+                       }
 
                        if (!skip_upload) {
                                /* Handle file */
@@ -928,10 +936,12 @@
 #else
                        s = strrchr(filename, '\\');
 #endif
-                       if (s && s > filename) {
-                               safe_php_register_variable(lbuf, s+1, NULL, 0 
TSRMLS_CC);
-                       } else {
-                               safe_php_register_variable(lbuf, filename, NULL, 0 
TSRMLS_CC);
+                       if (!is_anonymous) {
+                               if (s && s > filename) {
+                                       safe_php_register_variable(lbuf, s+1, NULL, 0 
+TSRMLS_CC);
+                               } else {
+                                       safe_php_register_variable(lbuf, filename, 
+NULL, 0 TSRMLS_CC);
+                               }
                        }
 
                        /* Add $foo[name] */
@@ -965,7 +975,9 @@
                        } else {
                                sprintf(lbuf, "%s_type", param);
                        }
-                       safe_php_register_variable(lbuf, cd, NULL, 0 TSRMLS_CC);
+                       if (!is_anonymous) {
+                               safe_php_register_variable(lbuf, cd, NULL, 0 
+TSRMLS_CC);
+                       }
 
                        /* Add $foo[type] */
                        if (is_arr_upload) {
@@ -987,7 +999,9 @@
                        magic_quotes_gpc = PG(magic_quotes_gpc);
                        PG(magic_quotes_gpc) = 0;
                        /* if param is of form xxx[.*] this will cut it to xxx */
-                       safe_php_register_variable(param, temp_filename, NULL, 1 
TSRMLS_CC);
+                       if (!is_anonymous) {
+                               safe_php_register_variable(param, temp_filename, NULL, 
+1 TSRMLS_CC);
+                       }
        
                        /* Add $foo[tmp_name] */
                        if (is_arr_upload) {
@@ -1028,7 +1042,9 @@
                                } else {
                                        sprintf(lbuf, "%s_size", param);
                                }
-                               safe_php_register_variable_ex(lbuf, &file_size, NULL, 
0 TSRMLS_CC);
+                               if (!is_anonymous) {
+                                       safe_php_register_variable_ex(lbuf, 
+&file_size, NULL, 0 TSRMLS_CC);
+                               }       
 
                                /* Add $foo[size] */
                                if (is_arr_upload) {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to