【问题标题】:jquery upload two files simultaneouslyjquery同时上传两个文件
【发布时间】:2015-07-20 12:01:04
【问题描述】:

是否可以通过将文件的 URL 传递给 FileReader 方法来上传文件? 问题是我将文档放在两页上 - 正面和背面(或侧面 - A 面和 B 面 - sasb),在图像中扫描,命名为 0001sa.jpg0001sb.jpg 等。我必须在浏览器中可视化它们的一部分,然后将它们的 URL-s 放入数据库中。

如果用户标记两个文件,这很容易:

function readURL(input) {
    if (input.files && input.files[0]) {

        filelst = input.files;        
        $("#pict_name").val( filelst[0].name);

        var reader = new FileReader();

        reader.onload = function (e) {              
            $('#imgPrev').attr('src', e.target.result).css('max-width', '2200px');
            $('#imgPrev').attr('data-zoom-image', e.target.result);
        //  imgPrev is the ID of the div, where I place the preview 
        // of part the image
        }

        reader.readAsDataURL(input.files[0]);

        var reader_b = new FileReader();
        reader_b.onload = function (eb) {
            $('#imgPrev1').attr('src', eb.target.result).css('max-width', '2100px');
            $('#imgPrev1').attr('data-zoom-image', eb.target.result);
            //I have to visualize different part of the back of the document
        }
        reader_b.readAsDataURL(input.files[1]);

    }
}

但是点击两个文件对操作者来说并不方便,而且 容易出错。如果我可以使用后面的 URL 来上传它,甚至可以将不同目录中的文件分开。 我可以做到这一点,还是FileReader 在这种情况下不是正确的方法?

【问题讨论】:

    标签: php jquery file upload filereader


    【解决方案1】:

    您可以使用 Ajax 上传多个文件。尝试通过 jQuery 使用 ajax 文件上传。还有许多基于 jQuery 的上传器可用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多