代码:
<?php
if(isset($_POST['submit']))
{
$filename = $_FILES['field']['name'];
$path = "attandance_file/".basename($_FILES['field']['name']);
$move = move_uploaded_file($_FILES['field']['tmp_name'],$path);
$data = file_get_contents($path, NULL, NULL, 0, 60000);
$query = "insert into attandance(No,TMNo,EnNo,Name,INOUT,Mode,DateTime)value('".$data."')";
echo $query;
unlink($path);
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" id="field" name="field" />
<input class="btn btn-info" type="submit" name="submit" id="submit" value="Submit" />
</form>
example.txt中:
No TMNo EnNo Name INOUT Mode DateTime
1 1 1 0 0 2017/01/03 16:41:22
2 1 1 0 0 2017/01/03 16:41:22
3 1 1 0 0 2017/01/03 16:42:39
4 1 1 0 0 2017/01/03 16:42:39
5 1 2 0 0 2017/01/03 16:59:42
当我点击提交按钮并回显$query
时,我得到的回复如下:
insert into attandance(No,TMNo,EnNo,Name,INOUT,Mode,DateTime)value('No TMNo EnNo Name INOUT Mode DateTime 1 1 1 0 0 2017/01/03 16:41:22 2 1 1 0 0 2017/01/03 16:41:22 3 1 1 0 0 2017/01/03 16:42:39 4 1 1 0 0 2017/01/03 16:42:39 5 1 2 0 0 2017/01/03 16:59:42')
如何使用PHP将example.txt文件上传到数据库?