我可以使用任何HTML或JavaScript API来获取input [type = file]中的文件路径吗? [英] Can I use any HTML or JavaScript API to get the file's path in input[type=file]?

查看:300
本文介绍了我可以使用任何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]中的文件路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆