我有以下 HTML 源代码:
<form name="AddTrack" id="add_track_form" action="AddTrack.aspx" method="post" runat="server">
<input type="file" name="file1"/><br />
<input type="file" style="margin-right: 52px;" name="file2" /><br />
<input type="file" style="margin-right: 52px;" name="file3" /><br />
<input type="file" style="margin-right: 52px;" name="file4" /><br />
<button type="submit" class="blue-button">הוסף מסלול</button>
</form>
使用此 ASPX - C# 代码:
if (Request.ContentLength != 0)
{
int Size = Request.Files[0].ContentLength / 1024;
if (Size <= 512)
{
string LocalFile = Request.Files[0].FileName;
int LastIndex = LocalFile.LastIndexOf(@"\") + 1;
string File = LocalFile.Substring(LastIndex, LocalFile.Length - LastIndex);
string Path = Server.MapPath(" ../images/tracks") + "..\\" + File;
Request.Files[0].SaveAs(Path);
Response.Write(@"The file was saved: " + Path);
}
else
{
Response.Write("The file is too big !");
}
}
else
{
Response.Write("Unknown Error !");
}
如果我上传一个文件,效果很好,但我上传的上传输入不止一个,它不起作用。
我的问题是为什么以及如何解决它?