加载csv并显示进度条或微调器

时间:2017-01-01 07:23:47

标签: php mysql csv

我试图显示一个进度条或类似的东西,只是为了让用户忙,而使用php从csv到mysql表的数据。下面是按下导入按钮时调用的代码:

if(isset($_POST['importSubmit'])){
    //validate whether uploaded file is a csv file
    $csvMimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv');
    if(!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'],$csvMimes)){
        if(is_uploaded_file($_FILES['file']['tmp_name'])){
            //open uploaded csv file with read only mode
            $csvFile = fopen($_FILES['file']['tmp_name'], 'r');
            //skip first line
            fgetcsv($csvFile);
            //parse data from csv file line by line
            while(($line = fgetcsv($csvFile)) !== FALSE){
                //insert member data into database
                $db->query("INSERT INTO members (name, email) VALUES ('".$line[0]."','".$line[1]."')");
            }
            //close opened csv file
            fclose($csvFile);
            echo $status_s;
        }else{
            echo $status_e;
        }
    }else{
        echo $status_f;
    }
}

0 个答案:

没有答案