tags:

views:

28

answers:

1

hello, i have a form that with a link click adds a new for a file with jquery's .html()

    // show div to change image on product_edit.php
    $("#change_img").click(
        function () {
            $("#change_img_div").html('<label>Image product</label><input type="file" value="" name="item_img" id="item_img"/>').fadeIn('fast');
            $(this).fadeOut('fast');

        }
    )

When I choose a file and I submit this name "item_img" is not present in the php $_POST array, if I put type="text" instead the new input is passed to POST.

Basically seems like a "file" type is not recognized if this is not present in the html if the first place?

+4  A: 

Files are sent as binary data and as per the HTML specification, it requires the <form> to be set with enctype="multipart/form-data" so that it can be mixed with text content (the normal request parameters). In the PHP side, they are available by the $_FILES array.

See also:

BalusC