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=
基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
