让我试着解释一下我的问题:
我正在尝试上传一个包含 10k+ 行的 scv 文件。无论如何,在这些行中可能会发生一些错误。
是否有可能为在文件仍在处理以导入数据库时发生的每个错误返回 JSON?
//编辑
好的,这是我的阅读代码
if (($handle = fopen('main_class/kur/'.$fileName, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 30000, ";")) !== FALSE) {
$row++;
foreach ($data AS $columns=>$val){
$data[$check->numberToColumnName($columns+1)]=$val;
unset($data[$columns]);
}
$FormtedData = $check->FormatAllData($data);
foreach ($FormtedData['vars'] AS $key=>$value){
$column_type = $check->CheckType($value,$key);
switch ($column_type){
case 'int' : $type=' int(11) unsigned NOT NULL ';
break;
case 'float' : $type=' FLOAT NOT NULL ';
break;
case 'TEXT' : $type=' TEXT NOT NULL ';
break;
case 'varchar' : $type=' VARCHAR( 255 ) NOT NULL ';
break;
default : ' int(11) unsigned NOT NULL ';
}
if ($row<3){
$check->addColumnIfItDoesNotExist($key,$type);
}
if ($column_type=='TEXT'){
$PreviousType = $check->SingleColumnType($key);
if ($PreviousType=='varchar(255)'){
$check->ChangeCoolumnType($key,$type);
}
}
}
$check->InsertValue($FormtedData['vars']);
/*
//$num = count($data);
//echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
//echo $data[$c] . "<br />\n";
}*/
$column++;
if ($check->numberToColumnName($num+1)==$column){
$column='A';
}
//end of while for each row
}
fclose($handle);
//end of open
}
这是我的上传者:
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader-demo1'),
action: '?func=FileUpload',
debug: false,
onProgress : function(a,b,c,d,e,f){
// dunno what is this :D
},
onComplete : function (a,b,json){
$.each(eval(json), function(i, item) {
console.log(i,'---',item,'<-');
});
},
});
}