如何使用angularjs和laravel 5.2上传文件?

时间:2016-06-13 13:15:18

标签: angularjs laravel laravel-5.2

我想使用angularjs

将图像上传到服务器
var fileInputElement = $('input[name=avatar]');
        var formData = new FormData();

        formData.append("team_name", $('input[name=team_name]').val());
        formData.append("associated_users", $('input[name=associated_users]').val()); // number 123456 is immediately converted to a string "123456"

// HTML file input, chosen by user
        formData.append("avatar", fileInputElement[0].files);
        $http.post('groups', formData)
            .then(
                function (response) {
                    console.log(response);
                    //$scope.teams.push(response.data)
                },
                function (response) {
                    console.log(response);
                }
            );

但在我的控制器中,当我像这样返回头像时:

 return "avatar =>" . Input::file('avatar');

结果是:

 data:"avatar =>"

我不知道这段代码有什么问题?

0 个答案:

没有答案