当Web服务器,此处假设为Apache(另外假设PHP是以module方式安装在Apache上的),接受到用户的数据时,首先它根据HTTP请求头,通过确定MIME TYPE为PHP类型,然后经过一些过程以后(这部分,可以参看我之前的PHP Life Cycle ppt),最终会把控制权交给PHP模块.
if ((cd = php_mime_get_hdr_value(header,"Content-Disposition"))) { char *pair=NULL; int end=0; while (isspace(*cd)) { ++cd; } while (*cd && (pair = php_ap_getword(&cd,';'))) { char *key=NULL,*word = pair; while (isspace(*cd)) { ++cd; } if (strchr(pair,'=')) { key = php_ap_getword(&pair,'='); if (!strcasecmp(key,"name")) { //获取name字段 if (param) { efree(param); } param = php_ap_getword_conf(&pair TSRMLS_CC); } else if (!strcasecmp(key,"filename")) { //获取filename字段 if (filename) { efree(filename); } filename = php_ap_getword_conf(&pair TSRMLS_CC); } } if (key) { efree(key); } efree(word); }
在这个过程中,PHP会去检查普通数据中,是否有MAX_FILE_SIZE.
/* Normal form variable,safe to read all data into memory */ if (!filename && param) { unsigned int value_len; char *value = multipart_buffer_read_body(mbuff,&value_len TSRMLS_CC); unsigned int new_val_len; /* Dummy variable */ ...... if (!strcasecmp(param,"MAX_FILE_SIZE")) { max_file_size = atol(value); } efree(param); efree(value); continue; }
有的话,就会按照它的值来检查文件大小是否超出.
if (PG(upload_max_filesize) > 0 && total_bytes > PG(upload_max_filesize)) { cancel_upload = UPLOAD_ERROR_A; } else if (max_file_size && (total_bytes > max_file_size)) { #if DEBUG_FILE_UPLOAD sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of %ld bytes exceeded - file [%s=%s] not saved", max_file_size,param,filename); #endif cancel_upload = UPLOAD_ERROR_B; }