我正在應用文件上傳大小限制,該用戶無法上傳超過30 MB的文件,並且如果超過了限制,則向他發送消息。 我正在使用以下代碼。在asp.net中應用服務器端的文件上傳大小限制C#
if (fileUpload.HasFile)
{
if (fileUpload.PostedFile.ContentLength < 30 * 1024 * 1024) // 30 MB
{
if (fileUpload.FileName != null && fileUpload.FileName != "")
{
UploadFile(fileUpload, "flv,mp3", out videoFileName, out uploadError);
if (uploadError != "")
{
lblMessage.Visible = true;
lblMessage.Text = uploadError;
return false;
}
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "File size exceeds the Limits. Please try uploading smaller size file.";
return false;
}
}
此代碼工作在Visual Studio很好,但是當我部署在IIS上的應用程序,它並沒有給我任何消息,如果我給超過30 MB的文件,並直接上傳文件。
我做錯了。
問候, 卡辛
但是這不限制用戶。 – Kash 2012-03-08 10:20:10
不,內置於瀏覽器的標準文件上傳控件不允許文件大小限制。你需要第三方(flash/applet/silverlight等)來做到這一點。 – 2012-03-08 12:18:42