以下代码假设将CSV文件上传到WAMP服务器,但它不是
<?php
@$con=mysql_connect("localhost","root","");
mysql_select_db("ddf",$con);
define('CSV_PATH','C:/Users/mshaikh/Desktop/Customs Compliance/CSV Files - 1000 Deposit/');
$csv_file = CSV_PATH . $_POST['t1'];
if (($getfile = fopen($csv_file, "r")) !== FALSE) {
$data = fgetcsv($getfile, 1000, ",");
while (($data = fgetcsv($getfile, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < 1; $c++) {
$result = $data;
$str = implode(",", $result);
$slice = explode(",", $str);
$col1 = $slice[0];
$col2 = $slice[1];
$col3 = $slice[2];
$col4 = $slice[3];
$col5 = $slice[4];
$col6 = $slice[5];
$col7 = $slice[6];
$col8 = $slice[7];
$col9 = $slice[8];
$col10 = $slice[9];
$col11 = $slice[10];
$col12 = $slice[11];
$col13 = $slice[12];
$col14 = $slice[13];
$col15 = $slice[14];
$col16 = $slice[15];
$col17 = $slice[16];
$col18 = $slice[17];
$col19 = $slice[18];
$col20 = $slice[19];
sql查询将csv插入到wamp
$query = "INSERT INTO pl(DELIVERYNO,PACK_NAME,PALLETNO,CARTONNO,ORDERREF,COO,UN_ID,MATERIAL_CODE,MATERIAL_DESC,QTY,MFG_CODE,SAP_BATCH,NET_WEIGHT,GROSS_WEIGHT,TOTAL_UNIT_NETWEIGHT,DIM_CM,TARIFF_NO,MATERIAL_NO,EANUPC,SHIP_QTY)
VALUES('".$col1."','".$col2."','".$col3."','".$col4."','".$col5."','".$col6."','".$col7."','".$col8."','".$col9."','".$col10."','".$col11."','".$col12."','".$col13."','".$col14."','".$col15."','".$col16."','".$col17."','".$col18."','".$col19."','".$col20."')";
$s=mysql_query($query, $con );
}
}
}
echo "File data successfully imported to database!!";
mysql_close($con);
?>