导入cvs文件的方法
来源:互联网 发布:ps cs6 mac中文破解版 编辑:程序博客网 时间:2024/05/06 01:40
页面:
<form action="insert.php" method="POST" enctype="multipart/form-data">
<input type="file" name="myfile" value="选择要导入的号码文件" />
<input type="submit" class="btn btn-info" value="导入" />
</form>
逻辑:
<?php
header("Content-type: text/html; charset=utf-8");
setlocale(LC_ALL,'null');
include_once('conn.php');
if(is_uploaded_file($_FILES['myfile']['tmp_name']))//is_uploaded_file()函数用来判断文件是否是post方式传过来的。
{ //$_FILES['myFile']['tmp_name'] 储存的临时文件名,一般是系统默认
$truename=$_FILES['myfile']['name'];//$_FILES['myFile']['name'] 显示客户端文件的原名称。
//获取文件后缀名
$type=substr($truename, strrpos($truename, "."));//strrpos()函数查找'.'在哪个位置,substr()函数,从固定位置开始,截取后一段字符串
$moveto_path=dirname(__FILE__)."/".time().$type; //这句话的意思就是某个路径下的某个文件
//move_uploaded_file函数用于将一个文件移到新的位置
if(move_uploaded_file($_FILES['myfile']['tmp_name'], $moveto_path)) //一个参数是暂时存放的地址,一个是将要移动到的地址
{
$temp=file($moveto_path);//连接EXCEL文件,格式为了.csv //file()把文件返回一个数组,每一行作为一个元素。
for ($i=0;$i <count($temp);$i++)
{
$string=explode(",",$temp[$i]);//通过循环得到EXCEL文件中每行记录的值
// 将EXCEL文件中每行记录的值插入到数据库中
$sql="insert into students (name, class, student_number, telephone) values('$string[0]','$string[1]','$string[2]','$string[3]')";
$q=mysql_query($sql);
$string = array();
}
if($q){
echo "<script>alert ('上传成功');window.location.href='interface.php';</script>";
}
else{
echo "<script>
alert('上传失败!');
</script>";
exit();
}
}
}
?>
- 导入cvs文件的方法
- oracle导入cvs文件方法
- 简单的excel cvs 文件导入功能
- CVS文件导入
- CVS文件导入导出
- Foxmail的cvs导入Ubuntu Thunderbird的方法
- 黑盒测试之导入CVS文件之什么是CVS文件
- CVS导入项目时某些文件不能正常导入的原因
- MySql数据导入导出cvs文件命令
- MySql数据导入导出cvs文件命令
- MySql数据库导入导出.cvs文件命令
- MyEclipse 导入cvs项目的java文件中文comments 为乱码,
- CocoaPods导入的库其头文件导入的方法
- 导入mdf文件的两种方法
- 将文件导入数据库的方法
- 各种数据库导入csv文件的方法
- shp文件导入mysql的方法总结
- Mysql导入xx.sql文件的方法
- Displaying Bitmaps in Your UI
- myeclispe 中deploy时不能出现deploy location?
- 由观察者模式的升级,得出委托代理
- SMP与Cluster的比较
- UVA File Fragmentation(文件复原)
- 导入cvs文件的方法
- 小怪物重制计划第六天
- MySql 问题解决整理
- Displaying Bitmap小结
- 计算两个字符串的距离
- Oracle回收站功能开启与关闭
- C语言下使用ringbuffer实现任意数据类型的FIFO
- 出国?上研?工作?回家种田?(一) 出国看世界
- ssh连接时提示“The authenticity of host xx can’t be ...