如何在php中上传和移动.txt文件

时间:2018-05-06 11:19:57

标签: php mysqli

代码:

<?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文件上传到数据库?

0 个答案:

没有答案