1

I got a field in my HTML that send a file.. When the user selects an image they get a preview of the image they are about to upload (js). When this preview script is activated the $_FILES post doesn't send any data (php verified with var_dump($_FILES)).

Here is the JS:

function readURL(input) {
if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function (e) {
        $('#preview')
            .attr('src', e.target.result)
            .css('display', 'block');
        $('#upload').html('<i class="icon-upload"></i> <input type="file" onchange="readURL(this);" size="1" name="foto" class="input-file" />Cambiar im&aacute;gen')
    };

    reader.readAsDataURL(input.files[0]); // <- If I delete this line it posts correctly but dosen't preview the image.
}

Someone sees the error?

j0k
  • 22,600
  • 28
  • 79
  • 90
  • Maybe a silly question, but which browser are you using? I believe at this time there is still only [**limited support**](https://developer.mozilla.org/en-US/docs/DOM/FileReader#Browser_compatibility) for FileReader() – Jared Cobb Oct 04 '12 at 22:19

1 Answers1

2

Actually it is html 5 feature i think. It will run surely on

Internet Explorer = 10+, Firefox: 10+, Chrome: 13+, Opera: 12+, Safari: partial

kaustubh
  • 79
  • 5