CVS update: php3/functions
| From: | brian | Date: | Thu, 10 Jun 1999 12:31:43 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6795@lists.php.net to get a copy of this message | ||
Date: Thursday June 10, 1999 @ 8:31
Author: brian
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv8124
Modified Files:
mime.c
Log Message:
Added support for file-upload arrays. Now supports $thefile[], $thefile_name[],
$thefile_size[], and $thefile_type[].
Index: php3/functions/mime.c
diff -u php3/functions/mime.c:1.56 php3/functions/mime.c:1.57
--- php3/functions/mime.c:1.56 Fri Jan 1 12:59:13 1999
+++ php3/functions/mime.c Thu Jun 10 08:31:40 1999
@@ -26,7 +26,7 @@
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
-/* $Id: mime.c,v 1.56 1999/01/01 17:59:13 zeev Exp $ */
+/* $Id: mime.c,v 1.57 1999/06/10 12:31:40 brian Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
@@ -44,7 +44,7 @@
#endif
#define NEW_BOUNDARY_CHECK 1
-#define SAFE_RETURN { if (namebuf) efree(namebuf); if (filenamebuf) efree(filenamebuf); if (lbuf)
efree(lbuf); return; }
+#define SAFE_RETURN { if (namebuf) efree(namebuf); if (filenamebuf) efree(filenamebuf); if (lbuf)
efree(lbuf); if (abuf) efree(abuf); return; }
/*
* Split raw mime stream up into appropriate components
@@ -54,7 +54,8 @@
char *ptr, *loc, *loc2, *s, *name, *filename, *u, *fn;
int len, state = 0, Done = 0, rem, urem;
long bytes, max_file_size = 0;
- char *namebuf=NULL, *filenamebuf=NULL, *lbuf=NULL;
+ char *namebuf=NULL, *filenamebuf=NULL, *lbuf=NULL, *abuf=NULL;
+ char sbytes[16];
FILE *fp;
int itype;
TLS_VARS;
@@ -104,7 +105,7 @@
if (lbuf) {
efree(lbuf);
}
- lbuf = emalloc(s-name +
MAX(MAX(sizeof("_name"),sizeof("_size")),sizeof("_type")));
+ lbuf = emalloc(s-name +
MAX(MAX(sizeof("_name"),sizeof("_size")),sizeof("_type")) + 4);
state = 2;
loc2 = memchr(loc + 1, '\n', rem);
rem -= (loc2 - ptr) + 1;
@@ -125,18 +126,32 @@
efree(filenamebuf);
}
filenamebuf = estrndup(filename, s-filename);
- sprintf(lbuf, "%s_name", namebuf);
+ if (strstr(namebuf, "[]")) {
+ if (abuf) {
+ efree(abuf);
+ }
+ abuf = estrndup(namebuf, strlen(namebuf) - 2);
+ sprintf(lbuf, "%s_name[]", abuf);
+ } else {
+ sprintf(lbuf, "%s_name", namebuf);
+ }
s = strrchr(filenamebuf, '\\');
if (s && s > filenamebuf) {
- SET_VAR_STRING(lbuf, estrdup(s + 1));
+ /* SET_VAR_STRING(lbuf, estrdup(s + 1)); */
+ _php3_parse_gpc_data(estrdup(s + 1), lbuf, http_post_vars);
} else {
- SET_VAR_STRING(lbuf, estrdup(filenamebuf));
+ /* SET_VAR_STRING(lbuf, estrdup(filenamebuf)); */
+ _php3_parse_gpc_data(estrdup(filenamebuf), lbuf, http_post_vars);
}
state = 3;
if ((loc2 - loc) > 2) {
if (!strncasecmp(loc + 1, "Content-Type:", 13)) {
*(loc2 - 1) = '\0';
- sprintf(lbuf, "%s_type", namebuf);
+ if (abuf) {
+ sprintf(lbuf, "%s_type[]", abuf);
+ } else {
+ sprintf(lbuf, "%s_type", namebuf);
+ }
SET_VAR_STRING(lbuf, estrdup(loc + 15));
*(loc2 - 1) = '\n';
}
@@ -208,14 +223,17 @@
if ((loc - ptr - 4) > php3_ini.upload_max_filesize) {
php3_error(E_WARNING, "Max file size of %ld bytes exceeded - file [%s] not saved",
php3_ini.upload_max_filesize,namebuf);
bytes=0;
- SET_VAR_STRING(namebuf, estrdup("none"));
+ /* SET_VAR_STRING(namebuf, estrdup("none")); */
+ _php3_parse_gpc_data(estrdup("none"), namebuf, http_post_vars);
} else if (max_file_size && ((loc - ptr - 4) > max_file_size)) {
php3_error(E_WARNING, "Max file size exceeded - file [%s] not saved", namebuf);
bytes = 0;
- SET_VAR_STRING(namebuf, estrdup("none"));
+ /* SET_VAR_STRING(namebuf, estrdup("none")); */
+ _php3_parse_gpc_data(estrdup("none"), namebuf, http_post_vars);
} else if ((loc - ptr - 4) <= 0) {
bytes = 0;
- SET_VAR_STRING(namebuf, estrdup("none"));
+ /* SET_VAR_STRING(namebuf, estrdup("none")); */
+ _php3_parse_gpc_data(estrdup("none"), namebuf, http_post_vars);
} else {
fp = fopen(fn, "w");
if (!fp) {
@@ -228,10 +246,21 @@
if (bytes < (loc - ptr - 4)) {
php3_error(E_WARNING, "Only %d bytes were written, expected to write %ld", bytes,
loc - ptr - 4);
}
- SET_VAR_STRING(namebuf, estrdup(fn));
+ /* SET_VAR_STRING(namebuf, estrdup(fn)); */
+ _php3_parse_gpc_data(estrdup(fn), namebuf, http_post_vars);
+ }
+
+ /* SET_VAR_LONG(lbuf, bytes); */
+
+ if (abuf) {
+ sprintf(lbuf, "%s_size[]", abuf);
+ } else {
+ sprintf(lbuf, "%s_size", namebuf);
}
- sprintf(lbuf, "%s_size", namebuf);
- SET_VAR_LONG(lbuf, bytes);
+ memset(sbytes, 0, 16);
+ sprintf(sbytes, "%ld", bytes);
+ _php3_parse_gpc_data(estrdup(sbytes), lbuf, http_post_vars);
+
state = 0;
rem -= (loc - ptr);
ptr = loc;