我正在尝试获取文本文件的内容,验证字符数不超过 60,000,然后将其插入数据库。如果超过 60,000 个字符,则应将其截断。
我怎样才能做到这一点?
最佳答案
<?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 - 上传 .txt 文件并将内容插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5366668/