Hi,
I have one problem with upload a file in server through Codeigniter
php Service and also I want to pass one "Id" to service, But i am not able
to pass here is my code
*Controller.js code*
var app = angular.module('angjs', ['ngRoute','angularFileUpload']);
app.factory("services", ['$http', function($http) {
var serviceBase = 'http://localhost:78/iblood/'
var obj = {};
obj.insertUser = function(register,files){
return $http.post(serviceBase + 'register/add', register).
success(function(data, status, headers, config){
var id=data.id;
var results = data.desc;
alert(results);
if(results=="DataInsertedSuccessfully"){
var url = 'http://localhost:78/iblood/register/uploadfile';
var fd = new FormData();
for ( var i = 0; i < files.length; i++)
{
fd.append("file", files[i]);
}
// var data1={id:id};
* fd.append("id", id);*
$http.post(url, fd, {
withCredentials : false,
headers : {
'Content-Type' : undefined
},
transformRequest : angular.identity
});
}
});
}
return obj;
}]);
app.controller('registerController', function ($scope,services) {
$scope.uploadedFile = function(element) {
$scope.$apply(function($scope) {
$scope.files = element.files;
});
}
$scope.saveRegister = function(register) {
services.insertUser(register,$scope.files).then(function(data){
$scope.response = data.data;
$scope.result=$scope.response.desc;
});
};
});
*Php Code*
function uploadfile(){
$target_dir = "upload/avatar/";
$filename = "koti"."-"."raju"."-".basename($_FILES["file"]["name"]);
$target_file = $target_dir . $filename;
move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);
$json_register= file_get_contents('php://input');
$registerdata = json_decode($json_register,true);
$post_donor_id = $registerdata['id'];
$arr = array(
'profilepic'=>$filename
);
$check = $this->donor_model->edit($arr,$post_donor_id);
if($check > 0)
{
$msg = "Data Updated Successfully";
header('Content-type: application/json');
$data = array('status' => "0",'desc' => $msg);
echo json_encode($data);
}
/*$filename = $_FILES['file']['name'];
$destination = 'http://localhost:78/iblood/assets/upload/avatar/' .
$filename;
move_uploaded_file( $_FILES['file']['tmp_name'] , $destination );*/
}
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.