项目是extjs2.2+SSH,之前做了用extjs做文件上传功能,实现方法是这样的:
控件就用的textfield,inputType为file,如
 var upload = new Ext.form.TextField({
fieldLabel : 'XXX',
name: 'upload',
allowBlank : false,
inputType:'file'
});该控件和其他控件一起在一个表单中,点击表单的保存时,触发表单的action进行保存操作,在action中调用一个自己写的上传文件方法。现在问题是:1.如何在extjs里面检验上传文件的大小,在用户点击上传时判断文件大小给予提示?
2.如何控制文件上传的大小?默认的好像是4M,我想将它改大一点。

解决方案 »

  1.   

    在<system.web>节点下加如下节点
    <httpRuntime maxRequestLength="10240000" />
    增加 maxRequestLength
      

  2.   

    呃具体的应该怎么实现呢?另外现在的项目是个Java的动态web项目,那个system.web应该在哪里啊?下面是项目里面的文件上传代码,大家看看可以怎么改?
    private static final int BUFFER_SIZE=16*1024;
    public static String upload(String uploadFileName, String savePath,
    File upload) {
    String fileName = uploadFileName;    
    File file = new File(savePath + "/" + uploadFileName);
    if (!file.getParentFile().exists()) {
    file.getParentFile().mkdirs();
    }
    if (file.exists()) { 
    String prefileName = getFileName(uploadFileName);
    String extension = getExtention(uploadFileName);
    int i = 1;
    while (file.exists()) {
    fileName = prefileName + i + extension;
    file = new File(savePath + "/" + fileName);
    i++;
    }
    }
    try {
    InputStream in = null;
    OutputStream out = null;
    try {
    in = new BufferedInputStream(new FileInputStream(upload),
    BUFFER_SIZE);
    out = new BufferedOutputStream(new FileOutputStream(file),
    BUFFER_SIZE);
    byte[] buffer = new byte[BUFFER_SIZE];
    for (int byteRead = 0; (byteRead = in.read(buffer)) > 0;) {
    out.write(buffer, 0, byteRead);
    } } finally {
    if (null != in) {
    in.close();
    }
    if (null != out) {
    out.close();
    }
    } } catch (Exception e) {
    e.printStackTrace();
    return "";
    }
    return fileName;
      

  3.   

    java没有 system.web 的配置,检查下看看是否有js代码配置限制
      

  4.   

    用FLASH来上传文件 和检查