Can I use any HTML or JavaScript API to get the file#39;s path in input[type=file]?(我可以使用任何 HTML 或 JavaScript API 在 input[type=file] 中获取文件的路径吗?)
问题描述
我想实现一个上传图片的功能.
I want to implement an upload image function.
上传后,我想获取文件本地路径,以便创建缩略图.但是我怎样才能得到文件路径呢?还有其他方法可以创建缩略图吗?
After uploading, I want get the file local path so I can create a thumbnail. But how can I get the file path? Is there another way to create the thumbnail?
我试过 jQuery-File-Upload 插件.
I have tried jQuery-File-Upload plugin.
推荐答案
我认为chrome支持这个,但不确定是否出于安全原因将其删除.无论如何你可以尝试使用javascrip来设置一些div的自定义宽度和高度并使用上传文件的 readAsDataURL
I think chrome supports this but not sure whether it is removed due to security reasons.Anyways you can try playing with javascrip to set custom width and height of some div and use readAsDataURL of the uploaded file
<script type="text/javascript">
function uploadFile(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#test').attr('src', e.target.result).width(100).height(100);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
<input type='file' onchange="uploadFile(this);" /> <img id="test" src="#" alt="my image" />
这篇关于我可以使用任何 HTML 或 JavaScript API 在 input[type=file] 中获取文件的路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我可以使用任何 HTML 或 JavaScript API 在 input[type=


基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01