【发布时间】:2016-02-06 18:27:45
【问题描述】:
试图用这个在数据库中上传图片
$file = $_FILES['image']['tmp_name'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size == false)
{
echo "Not an image";
}
else
{
mysqli_query($link, "INSERT into Events (imagetype, Attachments)
VALUES ('$image_name', '$image')");
}
connection.php 包含我的连接
试图用这个来检索图像:
include "connection.php";
$query = "SELECT imagetype,Attachments from Events where E_id='$id' ";
$result = mysqli_query($link,$query);
while ($row = mysqli_fetch_assoc($result))
{
header("Content-type:image/jpeg");
echo mysqli_result($row['Attachments'], 0);
}
【问题讨论】:
-
我已经有了。除非这是一个糟糕的粘贴
-
@ShubhamGupta 查看您的
mysqli_query声明。'image'与'$image'不同。 -
哦,还有一件事。您正在使用 MySQL 关键字
events,它会将其解释为函数,而不是表名声明 (2nd time I see this in 2 days) . dev.mysql.com/doc/refman/5.5/en/keywords.html - 需要特别注意。您的查询应该出错,但您没有检查。所以,这是对你的 2 次打击。 -
这里有太多未知数,无法为这个问题提供完整的解决方案。您可以自行调试代码并找出哪里出错了。请参阅以下链接 php.net/manual/en/mysqli.error.php 和 php.net/manual/en/function.error-reporting.php 并将其应用于您的代码。祝你好运。
-
@SubinThomas 这就是为什么我决定发布 cmets 而不是答案的原因,因为我知道并感觉到它在我的骨子里,这不足以解决他们的问题。有太多的未知数。 干杯,祝你好运。我希望这会得到解决。