php如何读取文件并写入数据库
<?php
/**************************
将本地文件上传并读取写入数据库
*************************/
require_once(../db_config_inc.php);//包含数据库处理类
if($_POST['up'])//如果提交了表单则执行下面操作
{
$filename = $_FILES['up_file']['tmp_name'];
$file = fopen($filename,'r') or die ("文件无法打开,请重试!");
while(!feof($file))
{
$rs = explode(" ",fgets($file));
$xh=$rs[1];
$xm=$rs[2];
$yx= $rs[3];
$bj = $rs[4];
$wp = $rs[5];
$bs = $rs[6];
$rw = $rs[7];
$rd = $rs[8];
$ds = $rs[9];
$fz = $rs[10];
$men = $rs[11];
$sql = "insert into infor 'xh','xm','yx','bj',wp','bs','rw','rd','ds','fz','men'values ($xh,$xm,$yx,$bj,$wp,$bs,$rw,$rd,$ds,$fz,$men);
$db->query($sql);
}
}
?>
转载于:https://www.cnblogs.com/bevan/archive/2009/08/09/1542358.html