显示选定的文件没有回传 [英] Show Selected File Without Postback

查看:115
本文介绍了显示选定的文件没有回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< input type =file> 其中用户选择一个图像文件。是否有可能在页面上显示这个图像,而不是实际上传到服务器?基本上我想要做的就是使用用户计算机上的本地文件。



PS - 我正在使用JQuery。

解决方案

使用 file:// 引用文件是不可能的,在文件输入框中,你只能得到文件名,而不是路径。所以不可能知道图像的位置。为了使它工作,你必须使用基于Flash的上传。



这当然是一个安全措施,因为Internet Explorer 给你是一个路径,唯一的事情是它总是 c:\ fakepath \filename.png 。我想浏览器正在做他们的工作,防止JavaScript从文件系统得到任何有意义的信息。


$ b 当试图上传文件 C:\test.txt :


  • Firefox 3.5.6

    test.txt


  • Chrome 3.0.195.38

    < / gt;>< p> Internet Explorer 8

    C:\\ bc \\ ctest \\ \\ fakepath \test.txt



I have an <input type="file"> where user selects an image file. Is it possible to show this image on a page without actually uploading it to the server first? Basically what I want to do is use the local file from the user's computer.

PS - I am using JQuery.

解决方案

It is impossible, even referencing to file using file:// won't work as when you get the value from the file input box, you only get the filename, not the path. So it's impossible to know where the image is located. To make it work, you'd have to use a Flash based uploader.

This is surely a safety measure, as Internet Explorer does give you a path, only thing is that it is always c:\fakepath\filename.png. I guess the browsers are doing their job preventing JavaScript from getting any meaningful information from the filesystem.

The return values for different browsers when trying to upload file C:\test.txt:

  • Firefox 3.5.6
    test.txt

  • Chrome 3.0.195.38
    test.txt

  • Opera 10.00
    C:\fake_path\test.txt

  • Internet Explorer 8
    C:\fakepath\test.txt

这篇关于显示选定的文件没有回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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