【问题标题】:PHP $_FILES are empty while the file is sent to server将文件发送到服务器时,PHP $_FILES 为空
【发布时间】:2015-05-03 04:43:28
【问题描述】:

我想使用https://github.com/danialfarid/ng-file-upload/ 进行文件上传。我正在尝试使用 $_FILES 全局数组来捕获上传的文件。当文件的内容被发送到服务器时,PHP 似乎无法捕获上传的文件元数据(文件名等)。所以 $_FILES 是空的。顺便说一句,我应该将文件和数据属性都设置为file

    $scope.upload = function (files) {
        if (files != null && files[0]) {
            var file = files[0];
            console.log(file);

            file.upload = Upload.http({
                url: 'rest/file/',
                data:file,
                fileName:'test',
                file: file
            });

            file.upload.then(function (response) {
                file.result = response.data;
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            });

            file.upload.progress(function (evt) {
                file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
            });
        }
    }

HTML 标记:

           <p>
                <label for="background">Background</label>
                <input ngf-select ngf-change="upload($files)" accept="image/*"
                       ng-model="form.background"
                       name="background" type="file"/>
                <img ng-show="form.background[0] != null" ngf-thumbnail="form.background[0]" class="thumb"/>
                        <span class="meter" ng-show="form.background[0].progress >= 0">
                                <span style="width:{{form.background[0].progress}}%"
                                      ng-bind="form.background[0].progress + '%'"
                                      class="ng-binding">
                                </span>
                        </span>

            </p>

【问题讨论】:

标签: php angularjs file upload


【解决方案1】:

检查 php.ini 中的 file_uploads = On、post_max_size 和 upload_max_file_size。也可以尝试增加 php.ini 中的 memory_limit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 2019-11-04
    • 2020-04-18
    • 2013-12-16
    • 1970-01-01
    相关资源
    最近更新 更多