PHP | Uploading and reading of files and database 【PHP | 文件的上传和读取与数据库】
这是我自己的一个作业,用的是很基础的代码。
有错误的地方欢迎批评和指正!
这里最容易出错的地方在读取数据后向数据库表中插入数据是的数据格式!
文件上传的页面
uploading.php
<html>
<body align = "center">
<form action = "DBConnect.php" method = "post" enctype = "multipart/form-data">
Upload a text file <input name = "myfile" type = "file" /></br></br>
<input type = "submit" value = "Upload this file"/></br></br>
</form>
<a href = "">Click here to find the format of text</a>
</body>
</html>
接收(对数据的读取)与对数据库的操作界面
DBConnect.php
<?php
$content = $_FILES['myfile']; // 对文件格式的读取,$_FILES方法
//print_r($content);
$string = file($content['name']);
//print_r($string);
//echo $string[0];
//exit(0);
$link = mysqli_connect("localhost","root","1234");
//create database sampleDB
mysqli_query($link,"create database $string[0]");
//create table mytbl
mysqli_query($link,"use $string[0]");
$tblQuery = "create table $string[1](";
$tblString="";
for($i=3;$i<count($string);$i++){
if(trim($string[$i]) == "row"){ // trim means remove space
break;
}else{
$col = explode(",",$string[$i]);
$tblString.=$col[0]." ".$col[1].",";
}
}
$tblQuery1 = $tblQuery.substr($tblString,0,-1).");";
mysqli_query($link,$tblQuery1);
//insert data to mytbl
$data = "insert into $string[1] values";
$data1String = "";
for($i=10;$i<count($string);$i++){
$data1 = explode(",",$string[$i]);
$data1String.="(".$data1[0].","."'".$data1[1]."'".",".$data1[2].",".$data1[3].","."'".$data1[4]."'".","."'".$data1[5]."'"." "."),";
}
// echo $data1String;
$tbldata = $data.substr($data1String,0,-1).";";
//echo $tbldata;
mysqli_query($link,$tbldata);
?>
info.txt 【这是你自己要读取的文件,里面的内容根据自己需求写】
sampleDB
mytbl
columns
sno,int
sname,varchar(15)
age,int
gender,boolean
address,text
cellphone,varchar(11)
row
1,john,12,0,california,1212111
2,alice,15,1,new york,1241512
3,cindy,13,1,LA,1251455
4,joshua,14,0,philadelphia,2154412
PHP | Uploading and reading of files and database 【PHP | 文件的上传和读取与数据库】的更多相关文章
- 多选文件批量上传前端(ajax*formdata)+后台(Request.Files[i])---input+ajax原生上传
1.配置Web.config;设定上传文件大小 <system.web> <!--上传1000M限制(https://www.cnblogs.com/Joans/p/4315411. ...
- java Files 和 Path对文件操作
1.拷贝文件 /** * 拷贝文件,生成新的文件名 * @param pathUpload * @return */ private String converUploadFileName(Strin ...
- Springboot 上传报错: Failed to parse multipart servlet request; nested exception is java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceede
Failed to parse multipart servlet request; nested exception is java.lang.IllegalStateException: The ...
- Reading Csv Files with Text_io in Oracle D2k Forms
Below is the example to read and import comma delimited csv file in oracle forms with D2k_Delimited_ ...
- [转]html5表单上传控件Files API
表单上传控件:<input type="file" />(IE9及以下不支持下面这些功能,其它浏览器最新版本均已支持.) 1.允许上传文件数量 允许选择多个文件:< ...
- 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?
复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...
- Asp.net上传文件Request.files获取不到文件
使用ftp上传文件,并且Request.files获取文件,今天发现获取到的文件个数始终是0个,查了下原来form标签中需加入enctype=”multipart/form-data”,呵呵了 < ...
- MVC文件上传 - 使用Request.Files上传多个文件
控制器 1: using System; 2: using System.Collections.Generic; 3: using System.IO; 4: using System.Linq; ...
- asp.net 页面上传文件控件后台代码Request.Files获取不到
今天开发中遇到页面文件上传控件选择了文件,而后台Request.Files.Count取值为0,之前开发中遇到过几次,老是忘掉,今天记下来. html: <input type="fi ...
随机推荐
- 从零开始的全栈工程师——html篇1.2
起名方式与CSS 一.起名方式(起名方式也叫选择器) 起名的目的是为了给标签添加属性 常见的3种选择器有 标签选择器 id选择器(使用的时候加#) class选择器(使用的时候加.) 样式的 ...
- ubuntu GITLAB完全导入SVN(提交历史,用户)项目
从SVN导入到GITLAB目前没有直接的方案,通常需要通过GIT转换:SVN –>GIT –>GITLAB.通过这种方式,将SVN的提交历史,用户信息一并导入到gitlab 注:本文只适用 ...
- C++基础--static的用法
首先,看看变量的存储: int global ; int main() { int stackStore ; int heapStore* = (int *)malloc(sizeof(int)); ...
- 关于scheduleAtFixedRate方法与scheduleWithFixedDelay的使用
一.scheduleAtFixedRate方法 该方法是ScheduledExecutorService中的方法,用来实现周期性执行给定的任务,public ScheduledFuture<?& ...
- OLAP和数据挖掘的区别
总结来说: 数据仓库提供了一个分析的数据源 数据挖掘能分析出未知的信息,提出假设 OLAP能通过分析,验证假设 从技术角度看,商务智能的过程是企业的决策人员以企业中的数据仓库为基础,经由数据挖掘工具. ...
- 一对多sql
<!-- 分页查询派货成本 --> <select id="queryCostRegionPriceBycondtion" parameterMap=" ...
- VSCode cpptools 插件在Centos 7下不能正确显示符号列表的解决办法
vscode 的插件cpptools 0.9.3 需要glibc 2.18的版本,但是Centos 7 下没有这个版本的GLIBC,所以导致链接库丢失,后台服务不能正常运行.按以下步骤操作可修复此问题 ...
- python入门18 继承和多态
继承:子类继承父类的属性和方法 class 子类名(父类1,父类2) 多态:子类重写父类的方法 判断对象是否是某个类的实例: isinstance(object,class) 父类-汽车类 #co ...
- Computer Hardware
Computer Hardware Para 1 Computer hardware can be divides into four categories: input hardware, stor ...
- IOS 触摸事件的处理
触摸事件的处理1.判断触摸点在谁身上: 调用所有UI控件的- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 2.pointIn ...