-2

I would like to show preview image without the image is being uploaded. Preferably if I can crop the image first, then show preview. What is the best way to do this? I heard this can be done with jquery and ajax. My website is using cakePHP.

Ary
  • 93
  • 2
  • 6

1 Answers1

0

The html code:

<input type="file" id="files" />
<img id="image" />

The JavaScript code:

document.getElementById("files").onchange = function () {
    var reader = new FileReader();

    reader.onload = function (e) {
        // get loaded data and render thumbnail.
        document.getElementById("image").src = e.target.result;
    };

    // read the image file as a data URL.
    reader.readAsDataURL(this.files[0]);
};

You may refer More Here

AdhershMNair
  • 2,603
  • 2
  • 16
  • 30