使用angular和php上传文件时遇到错误

时间:2019-04-04 10:04:52

标签: php angularjs

我正在从angularjs上传xls文件并在php上捕获,但是temp_name和大小为空

Angular js

$scope.uploadstock = function ($event) {

    if (typeof $event != "undefined") {
        $scope.uploads.user_file = $event.target.files[0];
    }
    $scope.stock_upload_loading = true;
    var fd = new FormData();
    fd.append("user_file", $scope.uploads.user_file);
    fd.append("data_source", $event.target.attributes.data_source.value);
    fd.append("saccount", $scope.firstAccId.id);

    FileUpload.getData(fd, bulk_stock_upload + "uploaduserfile").then(function (result) {
            result = result.data;
        if (result.code === 200) {
            $scope.handleUploadResponse(result);
            } else {
            if (result.code === 703 || result.code === 705
                || result.code === 702 || result.code === 704
                || result.code === 707 || result.code === 706
                || result.code === 708 || result.code === 701
                || result.code === 412
            ) {
                if (result.message === 'Invalid File Format') {
                    clevertap.event.push("Errors", {
                        "Type": "Incorrectfileformat",
                    });


                }


                }
            }
                $scope.fileerr = result.message;
            }
            $scope.stock_upload_loading = false;  
    });

};

PHP

print_r($_FILES);

进入下方

Array
(
    [user_file] => Array
        (
            [name] => stocks.xls
            [type] => 
            [tmp_name] => 
            [error] => 6
            [size] => 0
        )

)

由于缺少tmp_name,大小为0,因此我无法上传文件 请提出一些解决方案

1 个答案:

答案 0 :(得分:1)

错误代码6(UPLOAD_ERR_NO_TMP_DIR)在服务器上的临时文件夹上不存在。这个问题并非来自角度。您需要创建一个临时文件夹才能在服务器上上传文件。只需修复* .ini文件的设置即可。检查以下链接以获取更多信息:

http://php.net/manual/en/features.file-upload.errors.php

确定您的设置。

http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir