0

我正在使用ng-file-upload通过php上传mysql。

编码有效,但我无法访问自定义字段。有谁知道这是如何在 php 中访问的?See me code here 我正在添加字段描述:我想在 PHP 编码中恢复的成功。现在使用的访问方式$_FILES['file']['description'];NULL. 任何帮助将不胜感激。

JS

 $scope.upload = function (files) {
          console.log(files);
            if (files && files.length) {

            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                Upload.upload({
                    url: 'data/docmgmt/insert-docmgmt.php',
                    fields: {
                        'description': 'success'
                    },
                    file: file
                }).progress(function (evt) {
                    var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                    $scope.log = 'progress: ' + progressPercentage + '% ' +
                                evt.config.file.name + '\n' + $scope.log;
                }).success(function (data, status, headers, config) {
                    $scope.log = 'file ' + config.file.name + 'uploaded. Response: ' + JSON.stringify(data) + '\n' + $scope.log;
                    //$scope.$apply();
                });
            }
        }
    };

PHP

<?php
include('../config.php');

$doc_id = 0;
$fk_company_id = 0;
$name = "Test";
$description = $_FILES['file']['description'];
$filename = $_FILES['file']['name'];
$content = fopen($filename,'r');
fclose($filename);

session_start();

if(isset($_SESSION['uid'])) {

    if ($_SESSION['username'] =="admin") //check Admin
    {
            $dbname = $_SESSION['dbname'];
            try {
                $conn = new PDO("mysql:host=localhost;dbname=$dbname", $db->id, $db->pass); //connect to db
                $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    //error modes    

                    //insert user details
                    $stmt = $conn->prepare('INSERT INTO docmgmt(doc_id, fk_company_id, name, content, description) VALUES(:doc_id,:fk_company_id, :name, :content,:description)');
                    $stmt->bindParam(':doc_id', $doc_id, PDO::PARAM_INT);
                    $stmt->bindParam(':fk_company_id', $fk_company_id, PDO::PARAM_INT);
                    $stmt->bindParam(':name', $name, PDO::PARAM_STR);
                    $stmt->bindParam(':content', $content, PDO::PARAM_LOB);
                    $stmt->bindParam(':description', $description, PDO::PARAM_STR);
                    //$stmt->bindParam(':fk_created_by', $_SESSION['username'], PDO::PARAM_STR);
                    $stmt->execute(); 
                    $return->isSuccess=1;
                    $return->user_id= $user_id;

            }// end try 
            catch(PDOException $e) {
                $return->error = $e->getMessage();
            }//end catch
    }//end isset
}//end isset
print json_encode($return);

?>
4

1 回答 1

0

愚蠢的我。阅读自述文件它以表单数据的形式发送。因此访问描述:

$description = $_POST['description']
于 2015-05-15T06:35:47.060 回答