Web call Android, iphone camera, local pictures and files

Source: Internet
Author: User

In a previous company to do an app inside the upload avatar function, then studied for a long time, found an article about the H5 Camera and album calls, so it solved the problem!! I record here so that some people need, can refer to!!!!

The following is a complete HTML page content, placed on the server and then browse on it, only support chrome and Safari core browser, QQ browser, Chrome,safari browser can be. Different phones and browsers do not show the same way.

<! DOCTYPE html>
<title> Upload Images </title>
<meta charset= "Utf-8" >
<body>
<iframe name= "uploadfrm" id= "uploadfrm" style= "Display:none;" ></iframe>
<form name= "Formhead" method= "post" action= "id=" Formhead "enctype=" Multipart/form-data "target=" Uploadfrm ">

<div>
<div>
<input type= "File" Name= "File_head" id= "File_head" onchange= "Javascript:setimagepreview ();"/>
</div>
<div>
<div id= "Divup" style= "Display:none" >
<input type= "Submit" data-inline= "true" id= "Btnup" value= "Confirm upload" data-mini= "true"/>
</div>
</div>
</div>
</form>
<div data-role= "Fieldcontain" >
<div id= "Localimag" >

</div>
</div>


<script type= "Text/javascript" >
function Setimagepreview () {
var preview, Img_txt, localimag, File_head = document.getElementById ("File_head"),
Picture = File_head.value;
if (!picture.match (/.jpg|. Gif|. Png|. bmp/i) return alert ("The image you uploaded is not in the correct format, please re-select!") "),
!1;
if (preview = document.getElementById ("preview"), File_head.files && file_head.files[0]) Preview.style.display = "Block",
Preview.style.width = "63px",
Preview.style.height = "63px",
PREVIEW.SRC = Window.navigator.userAgent.indexOf ("Chrome") >= 1 | | Window.navigator.userAgent.indexOf ("Safari") >= 1? Window.webkitURL.createObjectURL (File_head.files[0]): window. Url.createobjecturl (File_head.files[0]);
else {
File_head.select (),
File_head.blur (),
Img_txt = Document.selection.createRange (). Text,
Localimag = document.getElementById ("Localimag"),
LocalImag.style.width = "63px",
LocalImag.style.height = "63px";
try {
LocalImag.style.filter = "Progid:DXImageTransform.Microsoft.AlphaImageLoader (Sizingmethod=scale)",
LocalImag.filters.item ("DXImageTransform.Microsoft.AlphaImageLoader"). src = img_txt
} catch (f) {
Return alert ("The image you uploaded is not in the correct format, please re-select!") "),
!1
}
Preview.style.display = "None",
Document.selection.empty ()
}
return document.getElementById ("Divup"). Style.display = "Block",
!0
}
</script>
</body>

Web call Android, iphone camera, local pictures and files

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.