Fix problems with file upload local path hiding in Chrome and Firefox

Source: Internet
Author: User

if you want to upload a picture, in the page to achieve a preview, you can get the file upload path, and then in a inside, the file upload path is <input type= The value of the "file"/>. In IE, the value is equal to the local path, however, in Chrome and Firefox, for security reasons, the path is anonymous, for example, upload e-disk readme.txt, the resulting value is c:/fakepath/readme.txt.

To display the uploaded image on the page, you can upload it to the server and then download it to avoid the problem, but there will be excess traffic, not a good practice.

Fortunately, I found a way to solve it:

<! doctype html public  "-//w3c//dtd xhtml 1.0 transitional//en"   "HTTP// Www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

call FileReader's Readasdataurl interface, will start the asynchronous loading file content, by listening to reader an onload event, after loading the data, in the OnLoad event processing, The contents of the file can be obtained by using the result property of reader.



Fix problems with file upload local path hiding in Chrome and Firefox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.