dua*_*ore 9 upload html5 image input
我正在尝试在html5中制作一个非常简单的图像上传器.
<input type="file" multiple=""/>
Run Code Online (Sandbox Code Playgroud)
我想做的就是在不使用PhP或任何东西的情况下显示上传的内容.我可以使用类似的代码吗?
<img src="WHATEVER WAS UPLOADED"/>
Run Code Online (Sandbox Code Playgroud)
谢谢!
小智 5
我发现
http://www.html5rocks.com/en/tutorials/file/dndfiles/
Run Code Online (Sandbox Code Playgroud)
相当有帮助.
如果您不想将图像推送到某个服务器(我假设您的问题),您可以在本地更新图像:
<style>
.thumb {
height: 75px;
border: 1px solid #000;
margin: 10px 5px 0 0;
}
</style>
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
Run Code Online (Sandbox Code Playgroud)
或者某些.
| 归档时间: |
|
| 查看次数: |
27505 次 |
| 最近记录: |