【问题标题】:Image wont upload mysqli图片不会上传mysqli
【发布时间】:2016-08-08 07:50:49
【问题描述】:

所以我有这个上传文件,将图像上传到数据库中。我已经很久没有使用 Mysqli 了,所以我不知道我是否做错了什么?

数据库表(封面):id(int 11),用户名(varchar 400),图像(longblob)。

<form action="insertimg.php" method="post" enctype="multipart/form-data">
    <input type="file" name="image" />
    <input type="submit" name="submit" id="submit" value="Submit Picture" />
</form>

这是上传文件:

$name = $_SESSION['Band_name'];

$imageData = file_get_contents($_FILES["image"]["tmp_name"]);
$imageType = $_FILES["image"]["type"];
if(substr($imageType,0,5) == "image"){

$query = "INSERT INTO cover VALUES ('', '$name', '$imageData')";

$db->query($query) or die('Error, query failed');
}

【问题讨论】:

  • 任何错误显示?
  • 运行代码时会发生什么?
  • 您可能希望使用file() 而不是file_get_contents(),因为后者将内容视为字符串而不是二进制数据。
  • 可以将内容作为字符串获取,file() 将返回数组,您无法将其正确存储在数据库中。尝试添加“{$imimageData}”。
  • 从我所看到的情况来看,您正在使用您的查询错误。在哪里指定要插入的列? INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)

标签: php image mysqli upload insert


【解决方案1】:

在 file_get_contents() 周围添加 addlashes 使其工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-25
    相关资源
    最近更新 更多