<?php
$fname = $_FILES['MyFile']['name'];
$do = copy($_FILES['MyFile']['tmp_name'],$fname);
if ($do){
echo"导入数据成功<br>";
}else{
echo "";
}
?>
<form ENCTYPE="multipart/form-data" ACTION="<?php echo"".$_SERVER["PHP_SELF"].""; ?>" METHOD="POST">
<p>导入CVS数据 <input NAME="MyFile" TYPE="file"> <input VALUE="提交" TYPE="submit">
</p>
</form>
<?php
error_reporting(0);//导入CSV格式的文件
$connect=
mysql_connect("localhost","a0530093319","123456") or die("could not connect to database");
mysql_select_db("a0530093319",$connect) or die (mysql_error());
$fname = $_FILES['MyFile']['name'];
$handle=fopen("$fname","r");
while($data=fgetcsv($handle,10000,",")){
$q="insert into test (code,name,date) values ('$data[0]','$data[1]','$data[2]')";
mysql_query($q) or die (mysql_error());
}
fclose($handle);
?>