[英]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.