上传.txt文件并将内容插入数据库(Upload .txt file and insert contents into a database)

编程入门 行业动态 更新时间:2024-10-25 14:28:54
上传.txt文件并将内容插入数据库(Upload .txt file and insert contents into a database)

我试图获取文本文件的内容,验证有60,000个字符或更少,并将其插入数据库。 如果有超过60,000个字符,则应将其截断。

我怎样才能做到这一点?

I am trying to grab the contents of a text file, verify that there are 60,000 characters or less, and insert that into a database. If there are more than 60,000 characters it should be truncated.

How can I achieve this?

最满意答案

<?php // db connection here // set path of uploaded file $path = "./".basename($_FILES['filename']['name']); // move file to current directory move_uploaded_file($_FILES['filename']['tmp_name'], $path)) { // get file contents $data = file_get_contents($path, NULL, NULL, 0, 60000); // run the query @mysql_query("INSERT INTO table (column) VALUES ('".$data."')"); // delete the file unlink($path); ?> <form enctype="multipart/form-data" action="" method="POST"> <input name="filename" type="file" /><br /> <input type="submit" value="upload file" /> </form> <?php // db connection here // set path of uploaded file $path = "./".basename($_FILES['filename']['name']); // move file to current directory move_uploaded_file($_FILES['filename']['tmp_name'], $path)) { // get file contents $data = file_get_contents($path, NULL, NULL, 0, 60000); // run the query @mysql_query("INSERT INTO table (column) VALUES ('".$data."')"); // delete the file unlink($path); ?> <form enctype="multipart/form-data" action="" method="POST"> <input name="filename" type="file" /><br /> <input type="submit" value="upload file" /> </form>

更多推荐

本文发布于:2023-07-28 18:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1307977.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并将   上传   数据库   文件   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!