我想将 CSV 文件上传到我的 SQL 数据库中,但收到“未定义的偏移量”错误。(偏移量:1-20)。不知道如何解决该错误。我希望你们能为我指出正确的方向。提前致谢。
<?php
// Load the database configuration file
include_once 'dbConfig.php';
if(isset($_POST['importSubmit'])){
// Allowed mime types
$csvMimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain');
// Validate whether selected file is a CSV file
if(!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'], $csvMimes)){
// If the file is uploaded
if(is_uploaded_file($_FILES['file']['tmp_name'])){
// Open uploaded CSV file with read-only mode
$csvFile = fopen($_FILES['file']['tmp_name'], 'r');
// Skip the first line
fgetcsv($csvFile);
// Parse data from CSV file line by line
while(($line = fgetcsv($csvFile)) !== FALSE){
// Get row data
$postcode = $line[0];
$week1 = $line[1];
$week2 = $line[2];
$week3 = $line[3];
$week4 = $line[4];
$week5 = $line[5];
$week6 = $line[6];
$week7 = $line[7];
$week8 = $line[8];
$week9 = $line[19];
$week10 = $line[10];
$week11 = $line[11];
$week12 = $line[12];
$week13 = $line[13];
$week14 = $line[14];
$week15 = $line[15];
$week16 = $line[16];
$week17 = $line[17];
$week18 = $line[18];
$week19 = $line[19];
$week20 = $line[20];
}
}
错误信息:

子衿沉夜
慕码人2483693
胡子哥哥
随时随地看视频慕课网APP