【发布时间】:2011-04-08 19:25:28
【问题描述】:
我的代码-
$filename = basename($_FILES['file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext=="txt")
&& ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{$newname = 'news/'.$filename;
move_uploaded_file($_FILES['file']['tmp_name'],$newname);
$fileread = $newname;
//reading a file
$file = fopen($fileread, "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
//inserting each data into table
$insert = "insert into $name (serial,data,used) values('','fgets($file)','0')";
$query = mysqli_query($connect,$insert);
if($query)
{
echo "cool";
}
}
所以用户上传包含每行数据的文本文件。我想将数据插入到数据库中,直到查询执行完毕。
插入 db 的是 fgets(Resource id #6) - 这一直持续到我停止。,..它不受控制...
【问题讨论】:
-
存在安全风险。据我所见,它正在抓取特定文件夹中的所有文本文件并阅读它们。任何文本文件都可以有任何内容。可能会发生 Mysql 注入,Marc B 对此进行了解释。
-
为什么要将文件的内容存储在数据库中?只需存储(大概)上传文件的文件名... o_O