PHP MySQL LOAD DATA INFILE Help

前端 未结 2 815
既然无缘
既然无缘 2021-01-21 03:13

I just can\'t seem to get this query right. Basically I\'m taking a csv from a form and trying to load it into the database. I took the majority of the query from phpmyadmin. i

2条回答
  •  孤城傲影
    2021-01-21 03:43

    Not sure why are you using that long-ass url for action instead of index.php or just ''? Also I think you need to specify ENCTYPE="multipart/form-data" since it's an upload form for a file. Not sure how to just just insert the file, I think you need to get contents of the file, then explode it and do insert

    $pfile = $_FILES['white']['name']; 
    $ptmpName  = $_FILES['white']['tmp_name']; 
    $fileSize = $_FILES['white']['size']; 
    $fileType = $_FILES['white']['type']; 
    $fp = fopen($ptmpName, 'r'); 
    $content = fread($fp, $fileSize); 
    $content = str_replace("\r\n", "\r", $content);
    $Data_Lines = explode("\r",$content);
    
    for ($n = 0; $n < (count($Data_Lines)-1);$n++){
    $line =  addslashes($Data_Lines[$n]); 
    $Value = explode(",",$line);
    ...//The you run insert  statements for $Value[1], $Value[2]...///
    

    }

    Or you can use fgetcsv - check this article: http://www.programmingfacts.com/import-csvexcel-data-mysql-database/

提交回复
热议问题