我需要在同一时间显示浏览图像,我使用了以下代码:
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.width(150)
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
<label for="FileID"><img id = "blah" style="width:100px;"src="http://lab.example.com/turn-key-mart/media/<?php echo $customer->getUserImage();?>"></label>
<input onchange="readURL(this);" style="width:0 !important;" name="file" type="file" id="FileID"/>
这在Chrome和Mozilla中运行良好,但在Safari中无效。
答案 0 :(得分:0)
请参阅此处http://caniuse.com/fileapi的文件阅读器API兼容性列表。它显示File Reader API在Safari中不起作用。
所以在你的代码中,你必须做这样的事情,
if ( typeof FileReader !== "undefined" ) {
// preview code here
} else {
// upload it using some ajax operations and return the file uri from server and set it to the DOM element
}
您可以尝试使用此polyfill来获取Safari中的功能。 https://github.com/Jahdrien/FileReader