0
ng-file-upload를 사용하여 파일을 업로드하고 파일의로드 데이터를 사용하여 테이블에 파일을 가져옵니다. 쉼표로 구분하여 완벽하게 작동하지만 세미콜론으로 구분하여 파일을 가져 오려고합니다.nara-file 업로드 지원 laravel 5.2 & Angular를 사용하여 가져올 세미콜론으로 구분 된 CSV 파일?
내 프론트 엔드는 각도이며, 백 엔드 laravel 5.2
여기이다 각도 JS laravel 컨트롤러에서
$scope.uploadPic = function(file){
console.log(Upload);
file.upload = Upload.upload({
url: API_BASE_URL + "panelist/import-panelist",
data: {
file: file,
username: $scope.username,
upload_type:$scope.panelistimport.upload_type,
panelist_status:$scope.panelistimport.panelist_status,
panel_id:1
},
});
file.upload.then(function (response) {
$timeout(function() {
file.result = response.data;
console.log(file.result);
});
}, function (response) {
if (response.status > 0) $scope.errorMsg = response.status + ': ' + response.data;
}, function (evt) {
// Math.min is to fix IE which reports 200% sometimes
file.progress = Math.min(100, parseInt(100.0 * evt.loaded/evt.total));
});
}
- 세미콜론으로 구분 된 작품 경우
가public function importPanelistData(Request $request){
if($request->file('file') && $request->input('panel_id')){
$file = $request->file('file');
$data1 = Array();
$data1 = array('panel_id' => $request->input('panel_id'),
'upload_type' => $request->input('upload_type'),
'panelist_status' => $request->input('panelist_status')
);
$originalName = $file->getClientOriginalName();
$name = time() . '-' . $originalName;
$storage = 'upload';
$path = $storage . '/csv';
// Moves file to folder on server
$file->move($path, $name);
$importPanelist = $this->importPanelist($path, $name ,$data1);
return Response::json($importPanelist ? $this->makeResponse("Panelist Imported successfully.",$originalName) : 'No rows affected');
}
}
public function importPanelist($path, $name ,$extraFields = array()){
$csv = $path . "/" . $name;
$query = "LOAD DATA LOCAL INFILE '$csv' INTO TABLE panelist FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (@col1,@col2,@col3,@col4,@col5,@col6,@col7,@col8,@col9,@col10,@col11,@col12,@col13,@col14) set [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],panel_id='".$extraFields['panel_id']."' ,status='".$extraFields['panelist_status']."' ";
return DB::connection()->getpdo()->exec($query);
}
이 나를 도와주세요 .