【发布时间】:2012-07-24 10:40:31
【问题描述】:
我有一个小图片上传脚本,它是一种用于多图片上传的脚本。
这是“提交后”的总数。问题是,上传后,图片的所有字段都是空的。没有一张图片不能在 sql 中看到。可能是什么问题?
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("127.0.0.1","root","");
if(!$conn)
{
echo mysql_error();
}
$db = mysql_select_db("newone",$conn);
if(!$db)
{
echo mysql_error();
}
$aphoto = addslashes(file_get_contents($_FILES['picone']['tmp_name']));
$aphoto = addslashes(file_get_contents($_FILES['pictwo']['tmp_name']));
$aphoto = addslashes(file_get_contents($_FILES['picthree']['tmp_name']));
$aphoto = addslashes(file_get_contents($_FILES['picfour']['tmp_name']));
$image = getimagesize($_FILES['picone']['tmp_name']); //to know about image type etc.
$image = getimagesize($_FILES['pictwo']['tmp_name']);
$image = getimagesize($_FILES['picthree']['tmp_name']);
$image = getimagesize($_FILES['picfour']['tmp_name']);
$q = "INSERT INTO pictures(picone, pictwo, picthree, picfour) Values('$picone','$pictwo','$picthree','$picfour')";
$r = mysql_query($q,$conn);
if($r)
{
header("Location: main.php");
echo "Information stored successfully";
}
else
{
echo mysql_error();
}
?>
【问题讨论】:
-
在数据库中存储图像不是一个很好的做法。改为存储图片的路径
-
必填项:您的查询容易受到 sql 注入,而且我很确定我可以上传一个 shell。清理和验证输入,否则您将被黑客入侵
-
好吧,我对你给我的建议很迷茫,基本上,我可以在我的脚本中添加这些保护性附加内容,但是,我不知道在哪里以及如何添加...其次,我不知道如何将图像保存到文件夹中并通过它的名称从那里调用数据库。您对我需要搜索的标签有任何想法,或者您可以描述我添加到脚本中的任何迹象吗?