📄 subject_34488.htm
字号:
<p>
序号:34488 发表者:kittyfish 发表日期:2003-03-30 18:56:08
<br>主题:[求助]文件上传的aspx怎么超过4M就不能传了?
<br>内容:求助。<BR>但是代码里面也没有什么限制的地方呀。<BR>搞了很久也没想通。<BR>真是郁闷。<BR>希望有高手指点,小弟不胜感激!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:kittyfish 回复日期:2003-03-30 18:58:40
<br>内容:我是用的HttpInputFile控件<BR>以及saveas语句.<BR>只能上传4M以下的。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:beiqiao 回复日期:2003-03-31 19:57:47
<br>内容:能否贴出代码
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:kittyfish 回复日期:2003-04-01 21:33:19
<br>内容:主要代码是:<BR> public void UploadFile(object sender , EventArgs E) <BR>{<BR>if(myFile.PostedFile!=null) <BR>{<BR>string nam=myFile.PostedFile.FileName ;<BR>int i= nam.LastIndexOf("\\") ; <BR>string newnm =nam.Substring(i) ; <BR>myFile.PostedFile.SaveAs("F:\\Upload\\"+newnm) ; <BR>//取得上传文件的各种属性。 <BR>fname.Text=myFile.PostedFile.FileName; <BR>fenc.Text=myFile.PostedFile.ContentType; <BR>fsize.Text=(myFile.PostedFile.ContentLength/1024).ToString(); <BR>}<BR>}<BR><BR>不知道为什么文件大于4M,就有问题。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:beiqiao 回复日期:2003-04-02 21:59:31
<br>内容:我试了试,的确如此<BR><BR>个人感觉是iis+asp.net的问题,asp.net的嫌疑更大些,可能是配置问题,也可能是微软自身的bug。<BR><BR>今天没有时间查了,抓紧最后一点时间cs一把,kittyfish兄弟如果已经解决了这个问题,也告诉我吧,谢谢
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:落叶夏日 回复日期:2003-04-03 12:36:15
<br>内容:我也在关注中,有了告诉我
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:兰兰的天空 回复日期:2003-04-05 18:19:06
<br>内容:不是吧,兄弟们。<BR>竟然是这样呀.............<BR>郁闷啦..........<BR>还有,怎么那么多人被接受为正确答案呀。<BR><BR>是不是要改用其他上传方式呀。<BR>比如说,用流(Stream);<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:落叶夏日 回复日期:2003-04-07 19:14:34
<br>内容:对,可以用其它方法,不过我也在关注这个,太大好象不可以
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:beiqiao 回复日期:2003-04-07 19:31:31
<br>内容:用HttpRequest.BinaryRead方法应该是可以地,下面是用上传文件的C处理方法,仅供参考<BR><BR><BR><BR>int FileSave(char *sFileName)<BR>{<BR> int amount;<BR> int loop;<BR> int cnt;<BR><BR> char *name, *value, *filename, *contenttype;<BR> int valuelen;<BR><BR> char boundary[256], boundaryEOF[256];<BR> char rnboundaryrn[256], rnboundaryEOF[256];<BR> int boundarylen, boundaryEOFlen, maxboundarylen;<BR><BR> char buf[1024];<BR> int i,c, c_count;<BR> int finish;<BR> FILE * fi;<BR> <BR><BR> if(sFileName == NULL || strlen(sFileName) ==0)<BR> {<BR> return 0;<BR> }<BR> <BR> if((fi = fopen(sFileName, "wb"))==NULL){<BR> return 0;<BR> };<BR> /* For parse multipart/form-data method */<BR> /* Force to check the boundary string length to defense overflow attack */<BR> maxboundarylen = strlen("--");<BR> maxboundarylen += strlen(strstr(getenv("CONTENT_TYPE"), "boundary=") + strlen("boundary="));<BR> maxboundarylen += strlen("--");<BR> maxboundarylen += strlen("\r\n");<BR> if(maxboundarylen >= sizeof(boundary)) printf("_parse_multipart_data(): The boundary string is too long. Stopping process.");<BR><BR> /* find boundary string */<BR> sprintf(boundary, "--%s", strstr(getenv("CONTENT_TYPE"), "boundary=") + strlen("boundary="));<BR> /* This is not necessary but, I can not trust MS Explore */<BR> qRemoveSpace(boundary);<BR><BR> sprintf(boundaryEOF, "%s--", boundary);<BR><BR> sprintf(rnboundaryrn, "\r\n%s\r\n", boundary);<BR> sprintf(rnboundaryEOF, "\r\n%s", boundaryEOF);<BR><BR> boundarylen = strlen(boundary);<BR> boundaryEOFlen = strlen(boundaryEOF);<BR> <BR> /* check boundary */<BR> <BR> if(_fgets(buf, sizeof(buf), stdin) == NULL) printf("_parse_multipart_data(): Your browser sent a non-HTTP compliant message.");<BR><BR> /* for explore 4.0 of NT, it sent \r\n before starting, f u cking Micro$oft */<BR> if(!strcmp(buf, "\r\n")) _fgets(buf, sizeof(buf), stdin);<BR><BR> if(strncmp(buf, boundary, boundarylen) != 0) printf("_parse_multipart_data(): String format invalid.");<BR> <BR> <BR> for(finish = 0, cnt = 0; finish != 1; amount++, cnt++) {<BR><BR> /* parse header */<BR> name = "";<BR> filename = "";<BR> contenttype = "";<BR><BR> while(_fgets(buf, sizeof(buf), stdin)) {<BR> if(!strcmp(buf, "\r\n")) break;<BR> else if(!qStrincmp(buf, "Content-Disposition: ", strlen("Content-Disposition: "))) {<BR> /* get name field */<BR> name = strdup(buf + strlen("Content-Disposition: form-data; name=\""));<BR> for(c_count = 0; (name[c_count] != '\"') && (name[c_count] != '\0'); c_count++);<BR> name[c_count] = '\0';<BR><BR> /* get filename field */<BR> if(strstr(buf, "; filename=\"") != NULL) {<BR> int erase;<BR> filename = strdup(strstr(buf, "; filename=\"") + strlen("; filename=\""));<BR> for(c_count = 0; (filename[c_count] != '\"') && (filename[c_count] != '\0'); c_count++);<BR> filename[c_count] = '\0';<BR> /* erase '\' */<BR> for(erase = 0, c_count = strlen(filename) - 1; c_count >= 0; c_count--) {<BR> if(erase == 1) filename[c_count]= ' ';<BR> else {<BR> if(filename[c_count] == '\\') {<BR> erase = 1;<BR> filename[c_count] = ' ';<BR> }<BR> }<BR> }<BR> qRemoveSpace(filename);<BR> }<BR> }<BR> else if(!qStrincmp(buf, "Content-Type: ", strlen("Content-Type: "))) {<BR> contenttype = strdup(buf + strlen("Content-Type: "));<BR> qRemoveSpace(contenttype);<BR> }<BR> }<BR> <BR> /* get value field */<BR> for(value = NULL, valuelen = (1024 * 16), c_count = 0; (c = fgetc(stdin)) != EOF; ) {<BR> if(c_count == 0) {<BR> value = (char *)malloc(sizeof(char) * valuelen);<BR> if(value == NULL) printf("_parse_multipart_data(): Memory allocation fail.");<BR> }<BR> else if(c_count == valuelen - 1) {<BR> char *valuetmp;<BR><BR> valuelen *= 2;<BR><BR> /* Here, we do not use realloc(). Because sometimes it is unstable. */<BR> valuetmp = (char *)malloc(sizeof(char) * valuelen);<BR> if(valuetmp == NULL) printf("_parse_multipart_data(): Memory allocation fail.");<BR> memcpy(valuetmp, value, c_count);<BR> free(value);<BR> value = valuetmp;<BR> }<BR> value[c_count++] = (char)c;<BR><BR> /* check end */<BR> if((c == '\n') || (c == '-')) {<BR> value[c_count] = '\0';<BR><BR> if((c_count - (2 + boundarylen + 2)) >= 0) {<BR> if(!strcmp(value + (c_count - (2 + boundarylen + 2)), rnboundaryrn)) {<BR> value[c_count - (2 + boundarylen + 2)] = '\0';<BR> valuelen = c_count - (2 + boundarylen + 2);<BR> break;<BR> }<BR> }<BR> if((c_count - (2 + boundaryEOFlen)) >= 0) {<BR> if(!strcmp(value + (c_count - (2 + boundaryEOFlen)), rnboundaryEOF)) {<BR> value[c_count - (2 + boundaryEOFlen)] = '\0';<BR> valuelen = c_count - (2 + boundaryEOFlen);<BR> finish = 1;<BR> break;<BR> }<BR> }<BR><BR> if((c_count - boundaryEOFlen) == 0) {<BR> if(!strcmp(value, boundaryEOF)) {<BR> value[0] = '\0';<BR> valuelen = 0;<BR> finish = 1;<BR> break;<BR> }<BR> }<BR> }<BR> }<BR> if(strcmp(filename, "") != 0)<BR> for(i = 0; i < valuelen; i++) fputc(*value++, fi); <BR> }<BR>fclose(fi);<BR>return 1;<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:落叶夏日 回复日期:2003-04-09 12:42:54
<br>内容:我找到答案了,不过不是我发现的,呵呵<BR>这是默认传输的最大数据量<BR>你在web.config里写入这些,其中maxRequestLength的值就是你要传的最大值<BR><configuration><BR><system.web><BR><httpRuntime maxRequestLength="614400"/><BR></system.web><BR></configuration><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:beiqiao 回复日期:2003-04-09 19:34:55
<br>内容:i see
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:兰兰的天空 回复日期:2003-04-15 17:59:21
<br>内容:非常感谢。<BR>我试一下。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -