无法使用 C# 上传 mp3,请帮忙
本文关键字:mp3 上传 | 更新日期: 2023-09-27 17:57:02
有人可以告诉我这段代码有什么问题吗?我正在尝试用这段代码上传mp3,当我尝试这样做时,我得到一个"Internet Explorer无法显示网页"
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="upload" runat="server" Text="GO" OnClick="btn_Click" /><br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<script runat="server">
protected void btn_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileExt =
System.IO.Path.GetExtension(FileUpload1.FileName);
if (fileExt == ".mp3")
{
try
{
FileUpload1.SaveAs(Server.MapPath("~/Uploads/" +
FileUpload1.FileName));
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "Only .mp3 files allowed!";
}
}
else
{
Label1.Text = "You have not specified a file.";
}
}
</script>
在你的web.config中使用以下命令增加http maxRequestLength - 它应该可以工作。默认情况下,它限制为 4mb。
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>