angularjs - ng-file-upload accessing fields in php -
i'm using ng-file-upload
upload mysql via php.
the coding works having trouble accessing custom fields. know how accessed in php? see me code here adding field description: success want recover in php coding. way accessing using $_files['file']['description'];
coming null
. appreciated.
js
$scope.upload = function (files) { console.log(files); if (files && files.length) { (var = 0; < 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 db $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); //error modes //insert user details $stmt = $conn->prepare('insert 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); ?>
stupid me. read readme sends s formdata. hence access description:
$description = $_post['description']
Comments
Post a Comment