[英]Blob datatype Image not stored in database
我正在尝试使用Blob数据类型将图像存储在数据库中。
但是我的程序没有将图像存储在数据库中。
码:
form.php的:
<form action="upload.php" method="post" enctype="multipart/form-data">
File Name<input type="file" name="image" /><br />
<input type="submit" value="Upload" />
</form>
upload.php的:
<?php
require_once('connection.php');
if(isset($_POST['submit'])){
$image = addslashes(file_get_contents($_FILES[image]['tmp_name']));
$query = "INSERT INTO images ('image') VALUES('".$image."')";
mysql_query($query) or die(mysql_error());
echo "Image id is ".mysql_insert_id();
echo "Image id is ".mysql_insert_id();
}
?>
请解决我的问题..
BLOB
最多可以存储65535 bytes
。 如果需要更多,请考虑将MEDIUMBLOB
用于16777215 bytes
或者将LONGBLOB
用于4294967295 bytes
。
查看字符串类型的存储要求 。
我的建议是使用LONGBLOB代替BLOB。 希望它能起作用。
尝试使用下面的代码。
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$query = "INSERT INTO images (image) VALUES('".$image."')";
我认为这一次工作很好...
尝试在fieldName上使用反引号
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
试试这个。这也是另一种存储斑点图像的方法。
码:
$image= $_FILES["image"];
$image= mysql_real_escape_string("$image");
$query = "INSERT INTO images (image) VALUES('".$image."')";
mysql_query($query) or die(mysql_error());
echo "Image id is ".mysql_insert_id();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.