![](/img/trans.png)
[英]Can I use JavaScript/JQuery to add an uploaded file to Request.Files in ASP.NET?
[英]Measure size of file uploaded using jQuery in ASP.NET
如何使用 jquery 测量文件大小,以下代码在 firefox、chrome 中运行良好,但在 IE (7/8/9) 中不起作用。 任何人都可以帮助我如何测量 IE 中的文件大小
var fi = document.getElementById('loadfile');
var sizeInMB = fi.files[0].size;
sizeInMB = (sizeInMB / (1024 * 1024));
if (sizeInMB > 20)
alert("File size more than 20MB");
else
alert("File size less than 20MB");
试试这样:
<script runat="server">
protected void UploadButton_Click(object sender, EventArgs e)
{
string savePath = @"c:\temp\uploads\";
if (FileUpload1.HasFile)
{
// Get the size in bytes of the file to upload.
int fileSize = FileUpload1.PostedFile.ContentLength;
// Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded.
if (fileSize < 2100000)
{
// Append the name of the uploaded file to the path.
savePath += Server.HtmlEncode(FileUpload1.FileName);
FileUpload1.SaveAs(savePath);
UploadStatusLabel.Text = "Your file was uploaded successfully.";
}
else
{
UploadStatusLabel.Text = "Your file was not uploaded because " +
"it exceeds the 2 MB size limit.";
}
}
else
{
UploadStatusLabel.Text = "You did not specify a file to upload.";
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.