2009-10-10 116 views
0

我已經與下面的標記HTML文件:需要了解爲什麼上傳不會在這種情況下發生?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
    <title>Upload Page</title> 
</head> 
<body> 
    <form id="frmUpload" action="UploadHandler.ashx" method="post" enctype="multipart/form-data">   
     <input type="file" /><br /> 
     <br /> 
     <input id="Submit1" type="submit" value="Submit" /> 
    </form> 
</body> 
</html> 

我有一個處理程序(ASHX)文件來處理這是這樣的上傳:

<%@ WebHandler Language="VB" Class="UploadHandler" %> 

Imports System 
Imports System.Web 
Imports System.Diagnostics 

Public Class UploadHandler : Implements IHttpHandler 

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest 
     Dim str As String 
     str = "EncType = " & context.Request.ContentType 
     str &= vbCrLf 
     str &= "File Count = " & context.Request.Files.Count 
     context.Response.ContentType = "text/plain" 
     context.Response.Write(str) 
    End Sub 

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable 
     Get 
      Return False 
     End Get 
    End Property 

End Class 

當我與工作html頁面,我選擇一個文件,並做了提交,我得到這樣的迴應:

EncType = multipart/form-data; boundary=---------------------------7d9232a130656 
File Count = 0 

我期待文件的數量爲1這裏卻是0 ...什麼是錯的?

回答

1

先給一個名字你輸入標籤:

<input type="file" name="fileToUpload" /> 
+0

所以我會與其他Web引擎類似的錯誤像PHP,紅寶石等...? – deostroll 2009-10-10 13:48:01

+1

是的。這與服務器端無關,任何瀏覽器都會忽略提交中未命名的字段。 – bobince 2009-10-10 18:23:17

1

你不必在你的文件<input>一個name屬性:

<input type="file" name="myFile"/><br /> 
相關問題