Невозможно получить имя загруженного файла, используя angularjs с переполнением стека

Я пытаюсь загрузить несколько файлов с другим названием, но не могу получить загруженные имена файлов.

Вот мой HTML-код.

 <div class="nav-md" ng-app="fileuploadModule">
<div class="container body" ng-controller="fileuploadController as parentCtrl">
<div class="form-group">
<div class="col-sm-6" style="padding:0px 10px 0px 0px;">
<label class="control-label">ID-NO</label>
<input type="text" class="form-control" id="idno" ng-model="idno" />

</div>
<div class="col-sm-6" style="padding:0px 10px 0px 0px;">
<label class="control-label" >Name</label>
<input type="text" class="form-control" id="pname" ng-model="pname" />
</div>
</div>
<div class="form-group" ng-controller="ChildController as childCtrl">
<div class="col-md-12" style="padding:0px 10px 0px 0px;">
<table ng-table="tableParams" class="display table table-striped table-bordered">
<thead>
<tr>
<th width="5%">Sr.No</th>
<th width="35%">Title</th>
<th width="35%">Upload Report</th>
<th width="25%"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="cap in data">
<td>{{$index+1}}</td>
<td>
<input class="form-control" id="tags" type="text" ng-model="cap.name" placeholder="Title" typeahead="drug.name for drug in drugArray | filter:$viewValue | limitTo:4">
</td>
<td>
<input type="file" id="i_file" name="file" ng-model="cap.file" ng-file-select="onFileSelect($files)" />
<input type="hidden" ng-model="cap.message" value={{message}} />
</td>
<td>
<input type="submit" ng-click="addFormField()" class="btn btn-default" value="Add Items" />
<input type="submit" value="Remove" class="btn btn-primary" ng-click="removeRow(cap.name)" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>

Вот сценарий angularjs.

 //reports upload
var infu = angular.module('fileuploadModule',['angularFileUpload','angularUtils.directives.dirPagination','ui.bootstrap'])
infu.controller('fileuploadController', function ($scope, $http)
{

/*Add & Remove Script Starts Here*/
//to remove the row
$scope.removeRow = function(name) {
var index = -1;
var comArr = eval( $scope.data );
for( var i = 0; i < comArr.length; i++ ) {
if( comArr[i].name ==name ) {
index = i;
break;
}
}
if( index === -1 ) {
}
$scope.data.splice( index, 1 );
};

//dynamic row creation
$scope.data = [{}];

//Autocomplete for title
$scope.drugArray = [];
$http({method: 'GET',url: 'get_test_name.php',data: { applicationId: 3 }}).success(function (data) {
$scope.drugArray = data;
});

$scope.addFormField = function() {
$scope.data.push({});
}
/*Add & Remove Script Ends Here*/


//Updated Investigation
$scope.submitData = function()
{
var comArr = eval( $scope.data );
var name=new Array();
var file=new Array();
var message=new Array();
for( var i = 0; i < comArr.length; i++ )
{
name.push(comArr[i].name);
file.push(comArr[i].file);
message.push(comArr[i].message);
}

var answer = confirm("Do you want to Submit?")
if (!answer)
{

}
else
{
$http.post('update_details.php', {
'idno': $scope.idno,
'pname': $scope.pname,
'name': name,
'file': file,
'message': message,
/*'filename': $scope.parentCtrl.childCtrl.message //If i give like getting only last upload file name*/
})
.success(function (data, status, headers, config)
{
alert("Data has been Added Successfully");
window.location.href="list_investigation_reports.php";
})

.error(function(data, status, headers, config)
{

});
}
}
});

//ChildController For file Upload
infu.controller('ChildController',function ($scope, $http, $upload) {
$scope.parentCtrl.childCtrl = $scope.childCtrl;
$scope.onFileSelect = function($files) {
$scope.message = "";
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
console.log(file);
$scope.upload = $upload.upload({
url: 'upload.php',
method: 'POST',
file: file
}).success(function(data, status, headers, config) {

$scope.message = data;
$scope.message=$scope.message.replace('\"', '');
$scope.childCtrl.message=$scope.message.replace('\"', '');
}).error(function(data, status) {
$scope.message = data;
});
}
};
});

Вот php код для загрузки файла

<?php
$target_dir = "uploadfiles/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);

$result = array("filename" => $_FILES["file"]);


$filename = $result['filename']['name'];
echo json_encode($filename);

?>

Вот окончательный код для вставки деталей в базу данных.

$data = json_decode(file_get_contents("php://input"));
$idno = $data->idno;
$pname = $data->pname;

$tname = $data->name;
$filename = $data->file;
$message = $data->message;

$date=date('Y-m-d');

foreach($tname as $index => $value)
{
$name1 = $tname[$index];
$filename1 = $filename[$index];
$message1 = $message[$index];

$qry_ress = $dbConnection->prepare("INSERT INTO tablename(idno,pname,testname,filename,cts) VALUES (?,?,?,?,?)");
$qry_ress->execute(array($idno,$pname,$name1,$filename1,$cts));

$arr = array("idno" => "$idno","pname" => "$pname","TestName" => "$name1","FileName" => "$filename1");
$jsn = json_encode($arr);
echo $jsn;
}

Получение результата, как показано ниже
{ «IDNO»: «20», «PNAME»: «Виджай», «АСМАП»: «Октябрь», «имя_файла»: «», «Сообщение»: «»} { «IDNO»: «PNAME «25» «:» Салим», «АСМАП»: «FFA», «FileName»: «», «Сообщение»: «»}

Получение вышеуказанных данных результата, кроме загруженного файла. Пожалуйста, помогите мне решить эту проблему.

Заранее спасибо.

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …