日期:2014-05-17  浏览次数:20437 次

请教 关于 用JS获取待上传文件大小的问题!
我想用JS获取待上传文件的大小,
  var image = new Image();
  image.dynsrc = src;
  alert(image.fileSize);
但IE8下提示dynsrc属性拒绝访问,请问如何解决,有没有别的方法啊?

------解决方案--------------------
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication1
{
  public partial class MainPage : UserControl
  {
    public MainPage()
    {
      InitializeComponent();
    }


    private void button1_Click(object sender, RoutedEventArgs e)
    {
      OpenFileDialog openFileDialog1 = new OpenFileDialog();
      openFileDialog1.Filter = "All files (*.*)|*.*";
      openFileDialog1.Multiselect = false;
      bool? userClickedOK = openFileDialog1.ShowDialog();
      if (userClickedOK == true)
      {
        System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
        MessageBox.Show(fileStream.Length.ToString());
        fileStream.Close();
      }
      openFileDialog1 = null;
    }

    
  }
}

------解决方案--------------------
Flash上传限制文件大小
http://demo.swfupload.org/Documentation/

File API得到文件大小
http://dotnet.aspx.cc/article/facbb9a7-c9c6-46ad-9591-5ba34ae27e58/read.aspx