有人知道如何加载图像(注意图像在服务器上)并将int作为blob插入数据库吗?说来话长,为什么我必须这样做。我已经尝试了$myfile = file_get_contents("image.png");
和打开,但是我在插入时遇到了问题。这是我必须使用的"古老"网络服务的一部分。
$result = mysql_query(
'INSERT INTO dogadjaj (host_id, name, description, date, photo)
VALUES ("' . $host_id . '" ,"' . $name .'", "' . $description . '", "' . $date . '", "' . $myfile . '");')
or die(mysql_error());
嗯,问题出在SQL查询中。如果要将文件从服务器放入数据库,请小心使用单引号。所以这就是需要完成的方式:
$result = mysql_query(
"INSERT INTO dogadjaj (host_id, name, description, date, photo)
VALUES ('" . $host_id . "' ,'" . $name ."', '" . $description . "', '" . $date . "', '" . mysql_escape_string(file_get_contents('myimage.png')) . "');")
or die(mysql_error());