Upload prin AJAX

Cotos Alexandru

Active Member
Registered
Full Member
Va rog frumos cu o parere ca m-a obosit problema !

Am codul HTML
----------------
HTML:
<input type="file" name="userImage" class="hidden" id="avatar" file-model="myFiles" accept="image/*">
Am codul PHP
---------------
Cod:
move_uploaded_file( $_FILES['userImage'] ['tmp_name'], $path);
Am codul Ajax
---------------
JavaScript:
$("document").ready(function() {
    $("input:file").change(function() {
        if (window.FormData !== undefined) {
            var i = $("#avatar").get(0),
                n = i.files,
                t = new FormData;
            t.append(n[0].name, n[0]);
            $.ajax({
                url: "/UploadAvatar",
                type: "POST",
                contentType: !1,
                processData: !1,
                data: t,
                success: function(n) {
                    n.length > 0 && ($(".user-img").css("background-image", "url('" + n + "')"), $(".user-avatar").attr("src", n))
                }
            })
        } else alert("FormData is not supported.")
    });
    $("#modifyAvatar").click(function(n) {
        n.preventDefault();
        $("#avatar").click()
    });
    $("#stergeAvatar").click(function(n) {
        n.preventDefault();
        $.ajax({
            url: "/stergeAvatar",
            type: "POST",
            contentType: !1,
            processData: !1,
            success: function(n) {
                $(".user-img").css("background-image", "url('" + n + "')");
                $(".user-avatar").attr("src", n)
            }
        })
    })
})
Nu inteleg de ce nu imi gaseste $_FILES['userImage'] (nu se uploadeaza ca spune ca nu s-a gasit specificatia)
 

Reclama

Topicuri Recomandate

  1. Platforma CPL Romania

Stiri Monezi Virtuale

Reducere pentru Vacanta

Loading...
Sus