【发布时间】:2015-07-20 12:01:04
【问题描述】:
是否可以通过将文件的 URL 传递给 FileReader 方法来上传文件?
问题是我将文档放在两页上 - 正面和背面(或侧面 - A 面和 B 面 - sa 和 sb),在图像中扫描,命名为 0001sa.jpg、0001sb.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