我要做的是使用angular和codeigniter 上传excel文件。 但问题是当我上传时它没有被CI功能接受,当我发送时状态代码是200,但是当我打印时我得到空数组
的print_r($ _ POST);的print_r($ _ FILES);
这是我的服务:
function UploadExcel(file,uploadUrl) {
var fd = new FormData();
fd.append('file', file);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': 'multipart/form-data'},
})
.success(function(){
})
.error(function(){
});
这是我的指示
app.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);
这是我的控制器
$scope.ImportApplicant = function() {
var file = $scope.myFile;
var uploadUrl = 'user/fileUpload';
UserService.UploadExcel(file, uploadUrl);
}
答案 0 :(得分:0)
对于角度代码
$scope.setFile1 = function(element)
{
$scope.currentFile = element.files[0];
var t = element.files[0].name;
var vali = t.split('.');
var length = vali.length-1;
var final = vali[length];
if(final=='txt' || final=='pdf' || final=='doc' || final=='docs')
{
var reader = new FileReader();
reader.onload = function(event)
{
$scope.missing.image = event.target.result
$scope.$apply();
$("#image_show").show();
}
reader.readAsDataURL(element.files[0]);
}
}
笨
$base64_string=$data['profile_image'];
if (preg_match('/base64/i', $base64_string))
{
$randomfile=time().'.jpeg';
$filename='./uploads/users/'.$randomfile;
$this->Cashback_model->base64_to_jpeg($base64_string, $filename);
}
else {
$file_name = explode('/', $base64_string);
foreach ($file_name as $keyval) {
$randomfile = $keyval;
}
}
模型
public function base64_to_jpeg($base64_string,$output_file) {
$ifp = fopen($output_file, "wb");
$data = explode(',', $base64_string);
fwrite($ifp, base64_decode($data[1]));
fclose($ifp);
return $output_file;
}