how do I get an image from an input file?

0

Someone tells me, what do I need to get a picture of the input file and show it or save it? Do I need to use javascript? or just the html and php?

I've researched google, but I'm not finding something explaining step by step, I've already tried it here, but I've only seen things a bit more specific ...

    
asked by anonymous 24.10.2015 / 00:52

1 answer

1

Preview before upload

To show a preview image before uploading, see below an example:

function ImagePreview(input)
{

    if (input.files && input.files[0])
	{

        var r = new FileReader();

        r.onload = function(e)
		{
			$("#img_preview").show();
            $("#img_preview").attr("src", e.target.result);
        }

        r.readAsDataURL(input.files[0]);

    }
}

$().ready(function() {

	hide_empty_image = false;
	set_blank_to_empty_image = false;
	set_image_border = true;

	if (hide_empty_image)
		$("#img_preview").hide();

	if (set_blank_to_empty_image)
		$("#img_preview").attr("src","data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=");

	if (set_image_border)
		$("#img_preview").css("border", "1px solid #05bbcc");
  
    $("#img_preview").css("width", "150px");
    $("#img_preview").css("height", "150px");

	$("#img_input").change(function(){
		ImagePreview(this);
	});

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formid="frm1">
    <input type="file" id="img_input" />
    <br /><img id="img_preview" src="" alt="Image Preview" />
</form>

To upload

There are hundreds of cases in StackOverflow, you can see this answer: link

If you want to find more results: link

    
24.10.2015 / 03:06