I've been looking into using html 5 <input type="file" accept="image/*" capture="camera">
to take a picture from my webapp and upload the image to the database using php - this is now working correctly.
However, the only way I can seem to find to display the "take picture" option is by a text field that has a button in it called "choose file"
Is there a way to be able to click on the existing image to open up the take picture options, then display the new image instead of the existing picture after the picture has been taken/file selected by the user? They should then click on the "upload" button if they are happy to save the image.
See JS fiddle here, hopefully this makes some sense! http://jsfiddle.net/6dxGY/
Using type="file" and accept="image/*" (or the format you want), allow the user to chose a file with specific format.
The accept attribute is incredibly useful. It is a hint to browsers to only show files that are allowed for the current input .
You have to use Javascript Filereader for this. (Introduction into filereader-api: http://www.html5rocks.com/en/tutorials/file/dndfiles/)
Once the user have choose a image you can read the file-path of the chosen image and place it into your html.
Example:
<form id="form1" runat="server"> <input type='file' id="imgInp" /> <img id="blah" src="#" alt="your image" /> </form>
Javascript:
function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('#blah').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); } } $("#imgInp").change(function(){ readURL(this); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With